dart-archive / observe

Support for marking objects as observable, and getting notifications when those objects are mutated
https://pub.dartlang.org/packages/observe
BSD 3-Clause "New" or "Revised" License
13 stars 6 forks source link

Optimize []= operator for ObservableMap when it has no observers #60

Closed DartBot closed 9 years ago

DartBot commented 9 years ago

Originally opened as dart-lang/sdk#17630

This issue was originally filed by ir...@google.com


ObservableMap's []= operator should not query the oldValue and length if there are no observers. For small maps, this is not an issue but if the request is being made to populate a huge map, this adds up when there are no observers.

@reflectable void operator []=(K key, V value) {     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));       }     }   }

DartBot commented 9 years ago

Comment by cbracken


cc @jmesserly. Added Pkg-Observe, Area-Polymer, Triaged labels.

DartBot commented 9 years ago

Comment by jmesserly


great catch! fixing :)


Added Started label.

DartBot commented 9 years ago

Comment by jmesserly


https://codereview.chromium.org/198993004/

DartBot commented 9 years ago

Comment by jmesserly


oops, landed bug forgot to close bug :)


Added Fixed label.