Skip to content

Commit

Permalink
perf(ddcd): optimize DirtyCheckingChangeDetector.collectChanges()
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Mar 10, 2014
1 parent b846138 commit 151eb76
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/dirty_checking.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export class DirtyCheckingChangeDetectorGroup extends ChangeDetector {
export class DirtyCheckingChangeDetector extends DirtyCheckingChangeDetectorGroup {
constructor(cache) {
super(null, cache);
this._fakeHead = DirtyCheckingRecord.marker();
}

_assertRecordsOk() {
Expand All @@ -209,18 +210,13 @@ export class DirtyCheckingChangeDetector extends DirtyCheckingChangeDetectorGrou
}
collectChanges(exceptionHandler, stopwatch) {
if (stopwatch) stopwatch.start();
var changeHead = null,
changeTail = null,
var changeTail = this._fakeHead,
current = this._recordHead,
count = 0;
while (current !== null) {
try {
if (current.check() !== null) {
if (changeHead !== null) {
changeTail = changeTail._nextChange = current;
} else {
changeHead = changeTail = current;
}
changeTail = changeTail._nextChange = current;
}
++count;
} catch (e) {
Expand All @@ -232,12 +228,12 @@ export class DirtyCheckingChangeDetector extends DirtyCheckingChangeDetectorGrou
}
current = current._nextRecord;
}
if (changeTail !== null) changeTail._nextChange = null;
changeTail._nextChange = null;
if (stopwatch) {
stopwatch.stop();
stopwatch.increment(count);
}
return changeHead;
return this._fakeHead._nextChange;
}
remove() {
throw "Root ChangeDetector can not be removed";
Expand Down

0 comments on commit 151eb76

Please sign in to comment.