Unverified Commit dacab7de authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

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

parent 79d4bdd1
...@@ -137,7 +137,7 @@ mixin AnimationLocalListenersMixin { ...@@ -137,7 +137,7 @@ mixin AnimationLocalListenersMixin {
@protected @protected
@pragma('vm:notify-debugger-on-exception') @pragma('vm:notify-debugger-on-exception')
void notifyListeners() { void notifyListeners() {
final List<VoidCallback> localListeners = List<VoidCallback>.of(_listeners); final List<VoidCallback> localListeners = _listeners.toList(growable: false);
for (final VoidCallback listener in localListeners) { for (final VoidCallback listener in localListeners) {
InformationCollector? collector; InformationCollector? collector;
assert(() { assert(() {
...@@ -226,7 +226,7 @@ mixin AnimationLocalStatusListenersMixin { ...@@ -226,7 +226,7 @@ mixin AnimationLocalStatusListenersMixin {
@protected @protected
@pragma('vm:notify-debugger-on-exception') @pragma('vm:notify-debugger-on-exception')
void notifyStatusListeners(AnimationStatus status) { 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) { for (final AnimationStatusListener listener in localListeners) {
try { try {
if (_statusListeners.contains(listener)) if (_statusListeners.contains(listener))
......
...@@ -76,6 +76,11 @@ class ObserverList<T> extends Iterable<T> { ...@@ -76,6 +76,11 @@ class ObserverList<T> extends Iterable<T> {
@override @override
bool get isNotEmpty => _list.isNotEmpty; 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. /// A list optimized for the observer pattern, but for larger numbers of observers.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment