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

Commit 4453e3e

Browse files
vicbmhevery
authored andcommitted
perf(change-detection): optimize DirtyCheckingChangeDetector.collectChanges()
Closes #693
1 parent c1937b4 commit 4453e3e

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lib/change_detection/dirty_checking_change_detector.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ class DirtyCheckingChangeDetectorGroup<H> implements ChangeDetectorGroup<H> {
247247

248248
class DirtyCheckingChangeDetector<H> extends DirtyCheckingChangeDetectorGroup<H>
249249
implements ChangeDetector<H> {
250+
251+
final DirtyCheckingRecord _fakeHead = new DirtyCheckingRecord.marker();
252+
250253
DirtyCheckingChangeDetector(GetterCache getterCache): super(null, getterCache);
251254

252255
DirtyCheckingChangeDetector get _root => this;
@@ -278,24 +281,17 @@ class DirtyCheckingChangeDetector<H> extends DirtyCheckingChangeDetectorGroup<H>
278281
return true;
279282
}
280283

281-
Iterator<Record<H>> collectChanges({ EvalExceptionHandler exceptionHandler,
282-
AvgStopwatch stopwatch}) {
284+
Iterator<Record<H>> collectChanges({EvalExceptionHandler exceptionHandler,
285+
AvgStopwatch stopwatch}) {
283286
if (stopwatch != null) stopwatch.start();
284-
DirtyCheckingRecord changeHead = null;
285-
DirtyCheckingRecord changeTail = null;
287+
DirtyCheckingRecord changeTail = _fakeHead;
286288
DirtyCheckingRecord current = _recordHead; // current index
287289

288290
int count = 0;
289291
while (current != null) {
290292
try {
291-
if (current.check()) {
292-
if (changeHead == null) {
293-
changeHead = changeTail = current;
294-
} else {
295-
changeTail = changeTail._nextChange = current;
296-
}
297-
}
298-
if (stopwatch != null) count++;
293+
if (current.check()) changeTail = changeTail._nextChange = current;
294+
count++;
299295
} catch (e, s) {
300296
if (exceptionHandler == null) {
301297
rethrow;
@@ -305,8 +301,12 @@ class DirtyCheckingChangeDetector<H> extends DirtyCheckingChangeDetectorGroup<H>
305301
}
306302
current = current._nextRecord;
307303
}
308-
if (changeTail != null) changeTail._nextChange = null;
304+
305+
changeTail._nextChange = null;
309306
if (stopwatch != null) stopwatch..stop()..increment(count);
307+
DirtyCheckingRecord changeHead = _fakeHead._nextChange;
308+
_fakeHead._nextChange = null;
309+
310310
return new _ChangeIterator(changeHead);
311311
}
312312

0 commit comments

Comments
 (0)