Improve efficiency of copying the animation ObserverList in notifyListeners (#102536)
This commit is contained in:
@@ -137,7 +137,7 @@ mixin AnimationLocalListenersMixin {
|
||||
@protected
|
||||
@pragma('vm:notify-debugger-on-exception')
|
||||
void notifyListeners() {
|
||||
final List<VoidCallback> localListeners = List<VoidCallback>.of(_listeners);
|
||||
final List<VoidCallback> localListeners = _listeners.toList(growable: false);
|
||||
for (final VoidCallback listener in localListeners) {
|
||||
InformationCollector? collector;
|
||||
assert(() {
|
||||
@@ -226,7 +226,7 @@ mixin AnimationLocalStatusListenersMixin {
|
||||
@protected
|
||||
@pragma('vm:notify-debugger-on-exception')
|
||||
void notifyStatusListeners(AnimationStatus status) {
|
||||
final List<AnimationStatusListener> localListeners = List<AnimationStatusListener>.of(_statusListeners);
|
||||
final List<AnimationStatusListener> localListeners = _statusListeners.toList(growable: false);
|
||||
for (final AnimationStatusListener listener in localListeners) {
|
||||
try {
|
||||
if (_statusListeners.contains(listener))
|
||||
|
||||
@@ -76,6 +76,11 @@ class ObserverList<T> extends Iterable<T> {
|
||||
|
||||
@override
|
||||
bool get isNotEmpty => _list.isNotEmpty;
|
||||
|
||||
@override
|
||||
List<T> toList({bool growable = true}) {
|
||||
return _list.toList(growable: growable);
|
||||
}
|
||||
}
|
||||
|
||||
/// A list optimized for the observer pattern, but for larger numbers of observers.
|
||||
|
||||
Reference in New Issue
Block a user