Skip to content

Commit

Permalink
perf(change-detection): optimize DirtyCheckingChangeDetector.collectC…
Browse files Browse the repository at this point in the history
…hanges()

Closes dart-archive#693
  • Loading branch information
vicb authored and mhevery committed Mar 7, 2014
1 parent c1937b4 commit 8aee9dd
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/change_detection/dirty_checking_change_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ class DirtyCheckingChangeDetectorGroup<H> implements ChangeDetectorGroup<H> {

class DirtyCheckingChangeDetector<H> extends DirtyCheckingChangeDetectorGroup<H>
implements ChangeDetector<H> {

final DirtyCheckingRecord _fakeHead = new DirtyCheckingRecord.marker();

DirtyCheckingChangeDetector(GetterCache getterCache): super(null, getterCache);

DirtyCheckingChangeDetector get _root => this;
Expand Down Expand Up @@ -278,24 +281,17 @@ class DirtyCheckingChangeDetector<H> extends DirtyCheckingChangeDetectorGroup<H>
return true;
}

Iterator<Record<H>> collectChanges({ EvalExceptionHandler exceptionHandler,
AvgStopwatch stopwatch}) {
Iterator<Record<H>> collectChanges({EvalExceptionHandler exceptionHandler,
AvgStopwatch stopwatch}) {
if (stopwatch != null) stopwatch.start();
DirtyCheckingRecord changeHead = null;
DirtyCheckingRecord changeTail = null;
DirtyCheckingRecord changeTail = _fakeHead;
DirtyCheckingRecord current = _recordHead; // current index

int count = 0;
while (current != null) {
try {
if (current.check()) {
if (changeHead == null) {
changeHead = changeTail = current;
} else {
changeTail = changeTail._nextChange = current;
}
}
if (stopwatch != null) count++;
if (current.check()) changeTail = changeTail._nextChange = current;
count++;
} catch (e, s) {
if (exceptionHandler == null) {
rethrow;
Expand All @@ -305,8 +301,12 @@ class DirtyCheckingChangeDetector<H> extends DirtyCheckingChangeDetectorGroup<H>
}
current = current._nextRecord;
}
if (changeTail != null) changeTail._nextChange = null;

changeTail._nextChange = null;
if (stopwatch != null) stopwatch..stop()..increment(count);
DirtyCheckingChangeDetector changeHead = _fakeHead._nextChange;
_fakeHead._nextChange = null;

return new _ChangeIterator(changeHead);
}

Expand Down

0 comments on commit 8aee9dd

Please sign in to comment.