Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Unified Diff: pkg/observe/lib/src/observable_map.dart

Issue 198993004: [observe] optimize ObservableMap setter if no observers are present (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: moar opt Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/observe/lib/src/observable_map.dart
diff --git a/pkg/observe/lib/src/observable_map.dart b/pkg/observe/lib/src/observable_map.dart
index c3a216fa8581bea7a65d1ea76eb92fee098a6565..a46c6450ee626f2528ac413bed699287246fc5df 100644
--- a/pkg/observe/lib/src/observable_map.dart
+++ b/pkg/observe/lib/src/observable_map.dart
@@ -105,16 +105,21 @@ class ObservableMap<K, V> extends ChangeNotifier implements Map<K, V> {
@reflectable V operator [](Object key) => _map[key];
@reflectable void operator []=(K key, V value) {
+ if (!hasObservers) {
+ _map[key] = value;
+ return;
+ }
+
int len = _map.length;
V oldValue = _map[key];
+
_map[key] = value;
- if (hasObservers) {
- if (len != _map.length) {
- notifyPropertyChange(#length, len, _map.length);
- notifyChange(new MapChangeRecord.insert(key, value));
- } else if (oldValue != value) {
- notifyChange(new MapChangeRecord(key, oldValue, value));
- }
+
+ if (len != _map.length) {
+ notifyPropertyChange(#length, len, _map.length);
+ notifyChange(new MapChangeRecord.insert(key, value));
+ } else if (oldValue != value) {
+ notifyChange(new MapChangeRecord(key, oldValue, value));
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698