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

perf(ddcd): optimize DirtyCheckingChangeDetector.collectChanges() #7

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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