@@ -68,12 +68,23 @@ class DirtyCheckingChangeDetectorGroup<H> implements ChangeDetectorGroup<H> {
68
68
return tail._recordTail;
69
69
}
70
70
71
+ bool get isAttached {
72
+ DirtyCheckingChangeDetectorGroup current = this ;
73
+ DirtyCheckingChangeDetectorGroup parent;
74
+ while ((parent = current._parent) != null ) {
75
+ current = parent;
76
+ }
77
+ return current is DirtyCheckingChangeDetector
78
+ ? true
79
+ : current._prev != null && current._next != null ;
80
+ }
81
+
71
82
72
83
DirtyCheckingChangeDetector get _root {
73
84
var root = this ;
74
- var next ;
75
- while ((next = root._parent) != null ) {
76
- root = next ;
85
+ var parent ;
86
+ while ((parent = root._parent) != null ) {
87
+ root = parent ;
77
88
}
78
89
return root is DirtyCheckingChangeDetector ? root : null ;
79
90
}
@@ -146,16 +157,12 @@ class DirtyCheckingChangeDetectorGroup<H> implements ChangeDetectorGroup<H> {
146
157
assert ((root = _root) != null );
147
158
assert (root._assertRecordsOk ());
148
159
DirtyCheckingRecord prevRecord = _recordHead._prevRecord;
149
- DirtyCheckingRecord nextRecord = _childInclRecordTail._nextRecord;
160
+ var childInclRecordTail = _childInclRecordTail;
161
+ DirtyCheckingRecord nextRecord = childInclRecordTail._nextRecord;
150
162
151
163
if (prevRecord != null ) prevRecord._nextRecord = nextRecord;
152
164
if (nextRecord != null ) nextRecord._prevRecord = prevRecord;
153
165
154
- var cursor = _recordHead;
155
- while (cursor != nextRecord) {
156
- cursor = cursor._nextRecord;
157
- }
158
-
159
166
var prevGroup = _prev;
160
167
var nextGroup = _next;
161
168
@@ -172,8 +179,7 @@ class DirtyCheckingChangeDetectorGroup<H> implements ChangeDetectorGroup<H> {
172
179
_parent = null ;
173
180
_prev = _next = null ;
174
181
_recordHead._prevRecord = null ;
175
- _recordTail._nextRecord = null ;
176
- _recordHead = _recordTail = null ;
182
+ childInclRecordTail._nextRecord = null ;
177
183
assert (root._assertRecordsOk ());
178
184
}
179
185
@@ -222,8 +228,8 @@ class DirtyCheckingChangeDetectorGroup<H> implements ChangeDetectorGroup<H> {
222
228
do {
223
229
allRecords.add (record.toString ());
224
230
record = record._nextRecord;
225
- }
226
- while (record != includeChildrenTail);
231
+ } while (record != includeChildrenTail);
232
+ allRecords. add ( includeChildrenTail);
227
233
lines.add ('FIELDS: ${allRecords .join (', ' )}' );
228
234
}
229
235
@@ -267,17 +273,42 @@ class DirtyCheckingChangeDetector<H> extends DirtyCheckingChangeDetectorGroup<H>
267
273
}
268
274
var groupRecord = group._recordHead;
269
275
var groupLast = group._recordTail;
270
- while (true ) {
276
+ if (record != groupRecord) {
277
+ throw "Next record is $record expecting $groupRecord " ;
278
+ }
279
+ var done = false ;
280
+ while (! done && groupRecord != null ) {
271
281
if (groupRecord == record) {
282
+ if (record._group != null && record._group != group) {
283
+ throw "Wrong group: $record "
284
+ "Got ${record ._group } Expecting: $group " ;
285
+ }
272
286
record = record._nextRecord;
273
287
} else {
274
288
throw 'lost: $record found $groupRecord \n $this ' ;
275
289
}
276
290
277
- if (groupRecord == groupLast) break ;
291
+ if (groupRecord._nextRecord != null &&
292
+ groupRecord._nextRecord._prevRecord != groupRecord) {
293
+ throw "prev/next pointer missmatch on "
294
+ "$groupRecord -> ${groupRecord ._nextRecord } "
295
+ "<= ${groupRecord ._nextRecord ._prevRecord } in $this " ;
296
+ }
297
+ if (groupRecord._prevRecord != null &&
298
+ groupRecord._prevRecord._nextRecord != groupRecord) {
299
+ throw "prev/next pointer missmatch on "
300
+ "$groupRecord -> ${groupRecord ._prevRecord } "
301
+ "<= ${groupRecord ._prevRecord ._nextChange } in $this " ;
302
+ }
303
+ if (groupRecord == groupLast) {
304
+ done = true ;
305
+ }
278
306
groupRecord = groupRecord._nextRecord;
279
307
}
280
308
}
309
+ if (record != null ) {
310
+ throw "Extra records at tail: $record on $this " ;
311
+ }
281
312
return true ;
282
313
}
283
314
0 commit comments