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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library observe.src.observable_map; 5 library observe.src.observable_map;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'package:observe/observe.dart'; 8 import 'package:observe/observe.dart';
9 9
10 10
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 @reflectable bool get isNotEmpty => !isEmpty; 99 @reflectable bool get isNotEmpty => !isEmpty;
100 100
101 @reflectable bool containsValue(Object value) => _map.containsValue(value); 101 @reflectable bool containsValue(Object value) => _map.containsValue(value);
102 102
103 @reflectable bool containsKey(Object key) => _map.containsKey(key); 103 @reflectable bool containsKey(Object key) => _map.containsKey(key);
104 104
105 @reflectable V operator [](Object key) => _map[key]; 105 @reflectable V operator [](Object key) => _map[key];
106 106
107 @reflectable void operator []=(K key, V value) { 107 @reflectable void operator []=(K key, V value) {
108 if (!hasObservers) {
109 _map[key] = value;
110 return;
111 }
112
108 int len = _map.length; 113 int len = _map.length;
109 V oldValue = _map[key]; 114 V oldValue = _map[key];
115
110 _map[key] = value; 116 _map[key] = value;
111 if (hasObservers) { 117
112 if (len != _map.length) { 118 if (len != _map.length) {
113 notifyPropertyChange(#length, len, _map.length); 119 notifyPropertyChange(#length, len, _map.length);
114 notifyChange(new MapChangeRecord.insert(key, value)); 120 notifyChange(new MapChangeRecord.insert(key, value));
115 } else if (oldValue != value) { 121 } else if (oldValue != value) {
116 notifyChange(new MapChangeRecord(key, oldValue, value)); 122 notifyChange(new MapChangeRecord(key, oldValue, value));
117 }
118 } 123 }
119 } 124 }
120 125
121 void addAll(Map<K, V> other) { 126 void addAll(Map<K, V> other) {
122 other.forEach((K key, V value) { this[key] = value; }); 127 other.forEach((K key, V value) { this[key] = value; });
123 } 128 }
124 129
125 V putIfAbsent(K key, V ifAbsent()) { 130 V putIfAbsent(K key, V ifAbsent()) {
126 int len = _map.length; 131 int len = _map.length;
127 V result = _map.putIfAbsent(key, ifAbsent); 132 V result = _map.putIfAbsent(key, ifAbsent);
(...skipping 22 matching lines...) Expand all
150 }); 155 });
151 notifyPropertyChange(#length, len, 0); 156 notifyPropertyChange(#length, len, 0);
152 } 157 }
153 _map.clear(); 158 _map.clear();
154 } 159 }
155 160
156 void forEach(void f(K key, V value)) => _map.forEach(f); 161 void forEach(void f(K key, V value)) => _map.forEach(f);
157 162
158 String toString() => Maps.mapToString(this); 163 String toString() => Maps.mapToString(this);
159 } 164 }
OLDNEW
« 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