From 21ae4e3e66c4f448701488623fc99a5e2bc170a0 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 5 Jun 2014 08:14:53 +0200 Subject: [PATCH 1/2] doc(dccd): update some comments see dartbug.com/18738 for details --- lib/change_detection/dirty_checking_change_detector.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/change_detection/dirty_checking_change_detector.dart b/lib/change_detection/dirty_checking_change_detector.dart index c927ff9dd..c297fcdfc 100644 --- a/lib/change_detection/dirty_checking_change_detector.dart +++ b/lib/change_detection/dirty_checking_change_detector.dart @@ -515,13 +515,13 @@ class DirtyCheckingRecord implements Record, WatchRecord { var last = currentValue; if (!identical(last, current)) { - if (last is String && current is String && - last == current) { + if (last is String && current is String && last == current) { // This is false change in strings we need to recover, and pretend it // is the same. We save the value so that next time identity will pass currentValue = current; } else if (last is num && last.isNaN && current is num && current.isNaN) { - // we need this for the compiled JavaScript since in JS NaN !== NaN. + // Doubles are identical iff they have the same representation as 64-bit IEEE floating + // point numbers. } else { previousValue = last; currentValue = current; @@ -1045,7 +1045,8 @@ class _CollectionChangeRecord implements CollectionChangeRecord { } if (item is num && (item as num).isNaN && record.item is num && (record.item as num).isNaN) { - // we need this for JavaScript since in JS NaN !== NaN. + // Doubles are identical iff they have the same representation as 64-bit IEEE floating + // point numbers. return record; } } From 5f19b47f798c1b2b42f393f77c5db7759f674337 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 6 Jun 2014 08:23:52 +0200 Subject: [PATCH 2/2] refactor(dccd): some renaming to clarify the intent --- .../dirty_checking_change_detector.dart | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/change_detection/dirty_checking_change_detector.dart b/lib/change_detection/dirty_checking_change_detector.dart index c297fcdfc..3a806ad7b 100644 --- a/lib/change_detection/dirty_checking_change_detector.dart +++ b/lib/change_detection/dirty_checking_change_detector.dart @@ -871,11 +871,11 @@ class _CollectionChangeRecord implements CollectionChangeRecord { Iterable _iterable; int _length; - /// Keeps track of moved items. - DuplicateMap _movedItems; + /// Keeps track of the used records at any point in time (during & across `_check()` calls) + DuplicateMap _linkedRecords; - /// Keeps track of removed items. - DuplicateMap _removedItems; + /// Keeps track of the removed records at any point in time during `_check()` calls. + DuplicateMap _unlinkedRecords; ItemRecord _previousItHead; ItemRecord _itHead, _itTail; @@ -886,7 +886,7 @@ class _CollectionChangeRecord implements CollectionChangeRecord { void _revertToPreviousState() { if (!isDirty) return; - if (_movedItems != null) _movedItems.clear(); + if (_linkedRecords != null) _linkedRecords.clear(); ItemRecord prev; int i = 0; @@ -897,8 +897,8 @@ class _CollectionChangeRecord implements CollectionChangeRecord { record._prev = prev; if (prev != null) prev._next = prev._nextPrevious = record; - if (_movedItems == null) _movedItems = new DuplicateMap(); - _movedItems.put(record); + if (_linkedRecords == null) _linkedRecords = new DuplicateMap(); + _linkedRecords.put(record); } prev._next = null; @@ -1063,13 +1063,13 @@ class _CollectionChangeRecord implements CollectionChangeRecord { } // Attempt to see if we have seen the item before. - record = _movedItems == null ? null : _movedItems.get(item, index); + record = _linkedRecords == null ? null : _linkedRecords.get(item, index); if (record != null) { // We have seen this before, we need to move it forward in the collection. _moveAfter(record, previousRecord, index); } else { // Never seen it, check evicted list. - record = _removedItems == null ? null : _removedItems.get(item); + record = _unlinkedRecords == null ? null : _unlinkedRecords.get(item); if (record != null) { // It is an item which we have evicted earlier: reinsert it back into the list. _reinsertAfter(record, previousRecord, index); @@ -1108,7 +1108,7 @@ class _CollectionChangeRecord implements CollectionChangeRecord { * of 'b' rather then switch 'a' with 'b' and then add 'a' at the end. */ ItemRecord verifyReinsertion(ItemRecord record, item, int index) { - ItemRecord reinsertRecord = _removedItems == null ? null : _removedItems.get(item); + ItemRecord reinsertRecord = _unlinkedRecords == null ? null : _unlinkedRecords.get(item); if (reinsertRecord != null) { record = _reinsertAfter(reinsertRecord, record._prev, index); } else if (record.currentIndex != index) { @@ -1130,7 +1130,7 @@ class _CollectionChangeRecord implements CollectionChangeRecord { _addToRemovals(_unlink(record)); record = nextRecord; } - if (_removedItems != null) _removedItems.clear(); + if (_unlinkedRecords != null) _unlinkedRecords.clear(); if (_additionsTail != null) _additionsTail._nextAdded = null; if (_movesTail != null) _movesTail._nextMoved = null; @@ -1139,7 +1139,7 @@ class _CollectionChangeRecord implements CollectionChangeRecord { } ItemRecord _reinsertAfter(ItemRecord record, ItemRecord prevRecord, int index) { - if (_removedItems != null) _removedItems.remove(record); + if (_unlinkedRecords != null) _unlinkedRecords.remove(record); var prev = record._prevRemoved; var next = record._nextRemoved; @@ -1201,9 +1201,9 @@ class _CollectionChangeRecord implements CollectionChangeRecord { prevRecord._next = record; } - if (_movedItems == null) _movedItems = new DuplicateMap(); + if (_linkedRecords == null) _linkedRecords = new DuplicateMap(); + _linkedRecords.put(record); - _movedItems.put(record); record.currentIndex = index; return record; } @@ -1211,7 +1211,7 @@ class _CollectionChangeRecord implements CollectionChangeRecord { ItemRecord _remove(ItemRecord record) => _addToRemovals(_unlink(record)); ItemRecord _unlink(ItemRecord record) { - if (_movedItems != null) _movedItems.remove(record); + if (_linkedRecords != null) _linkedRecords.remove(record); var prev = record._prev; var next = record._next; @@ -1250,8 +1250,8 @@ class _CollectionChangeRecord implements CollectionChangeRecord { } ItemRecord _addToRemovals(ItemRecord record) { - if (_removedItems == null) _removedItems = new DuplicateMap(); - _removedItems.put(record); + if (_unlinkedRecords == null) _unlinkedRecords = new DuplicateMap(); + _unlinkedRecords.put(record); record.currentIndex = null; record._nextRemoved = null;