Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
refactor(dccd): Drop the insertBefore arg from DuplicateMap.put()
Browse files Browse the repository at this point in the history
Fixes #1128
Closes #1132

The insertBefore argument is never used in the current code
  • Loading branch information
vicb committed Jul 31, 2014
1 parent 209d14f commit f54451b
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions lib/change_detection/dirty_checking_change_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1303,40 +1303,22 @@ class _DuplicateItemRecordList {
ItemRecord _head, _tail;

/**
* Add the [record] before the [insertBefore] in the list of duplicates or at the end of the list
* when no [insertBefore] is specified.
* Append the [record] to the list of duplicates.
*
* Note: by design all records in the list of duplicates hold the save value in [record.item].
*/
void add(ItemRecord record, ItemRecord insertBefore) {
assert(insertBefore == null || insertBefore.item == record.item);
void add(ItemRecord record) {
if (_head == null) {
/// pushing the first [ItemRecord] to the list
assert(insertBefore == null);
_head = _tail = record;
record._nextDup = null;
record._prevDup = null;
} else {
// adding a duplicate [ItemRecord] to the list
assert(record.item == _head.item ||
record.item is num && record.item.isNaN && _head.item is num && _head.item.isNaN);
if (insertBefore == null) {
_tail._nextDup = record;
record._prevDup = _tail;
record._nextDup = null;
_tail = record;
} else {
var prev = insertBefore._prevDup;
var next = insertBefore;
record._prevDup = prev;
record._nextDup = next;
if (prev == null) {
_head = record;
} else {
prev._nextDup = record;
}
next._prevDup = record;
}
_tail._nextDup = record;
record._prevDup = _tail;
record._nextDup = null;
_tail = record;
}
}

Expand Down Expand Up @@ -1390,16 +1372,16 @@ class _DuplicateItemRecordList {
* The list of duplicates is implemented by [_DuplicateItemRecordList].
*/
class DuplicateMap {
static final nanKey = const Object();
static final _nanKey = const Object();
final map = new HashMap<dynamic, _DuplicateItemRecordList>();

void put(ItemRecord record, [ItemRecord insertBefore = null]) {
void put(ItemRecord record) {
var key = _getKey(record.item);
_DuplicateItemRecordList duplicates = map[key];
if (duplicates == null) {
duplicates = map[key] = new _DuplicateItemRecordList();
}
duplicates.add(record, insertBefore);
duplicates.add(record);
}

/**
Expand Down Expand Up @@ -1436,7 +1418,7 @@ class DuplicateMap {
}

/// Required to handle num.NAN as a Map value
dynamic _getKey(value) => value is num && value.isNaN ? nanKey : value;
dynamic _getKey(value) => value is num && value.isNaN ? _nanKey : value;

String toString() => "DuplicateMap($map)";
}
Expand Down

0 comments on commit f54451b

Please sign in to comment.