Improve efficiency of copying the animation ObserverList in notifyListeners (#102536)

This commit is contained in:
Jason Simmons
2022-04-26 13:29:08 -07:00
committed by GitHub
parent 79d4bdd159
commit dacab7de3a
2 changed files with 7 additions and 2 deletions

View File

@@ -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))

View File

@@ -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.