Skip to content

Commit

Permalink
Improve efficiency of copying the animation ObserverList in notifyLis…
Browse files Browse the repository at this point in the history
…teners (#102536)
  • Loading branch information
jason-simmons authored Apr 26, 2022
1 parent 79d4bdd commit dacab7d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/animation/listener_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(() {
Expand Down Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions packages/flutter/lib/src/foundation/observer_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit dacab7d

Please sign in to comment.