@@ -258,68 +258,87 @@ function linkNewDep(
258
258
return newLink
259
259
}
260
260
261
- function checkDirty ( current : Link ) : boolean {
262
- let prevLinks : OneWayLink < Link > | undefined
263
- let checkDepth = 0
261
+ function checkDirty ( link : Link ) : boolean {
262
+ let stack = 0
263
+ let dirty : boolean
264
264
265
265
top: do {
266
- const dep = current . dep
266
+ dirty = false
267
+ const dep = link . dep
267
268
268
269
if ( 'flags' in dep ) {
269
270
const depFlags = dep . flags
270
271
if (
271
272
( depFlags & ( SubscriberFlags . Computed | SubscriberFlags . Dirty ) ) ===
272
273
( SubscriberFlags . Computed | SubscriberFlags . Dirty )
273
274
) {
274
- if ( dep . update ( ) ) {
275
- if ( current . nextSub !== undefined || current . prevSub !== undefined ) {
276
- shallowPropagate ( dep . subs ! )
275
+ if ( ( dep as Computed ) . update ( ) ) {
276
+ const subs = dep . subs !
277
+ if ( subs . nextSub !== undefined ) {
278
+ shallowPropagate ( subs )
277
279
}
278
- while ( checkDepth -- ) {
279
- const computed = current . sub as Computed
280
- const firstSub = computed . subs !
281
-
282
- if ( computed . update ( ) ) {
283
- if ( firstSub . nextSub !== undefined ) {
284
- shallowPropagate ( firstSub )
285
- current = prevLinks ! . target
286
- prevLinks = prevLinks ! . linked
287
- } else {
288
- current = firstSub
289
- }
290
- continue
291
- }
292
-
293
- if ( firstSub . nextSub !== undefined ) {
294
- if ( ( current = prevLinks ! . target . nextDep ! ) === undefined ) {
295
- return false
296
- }
297
- prevLinks = prevLinks ! . linked
298
- continue top
299
- }
300
-
301
- return false
302
- }
303
- return true
280
+ dirty = true
304
281
}
305
282
} else if (
306
283
( depFlags &
307
284
( SubscriberFlags . Computed | SubscriberFlags . PendingComputed ) ) ===
308
285
( SubscriberFlags . Computed | SubscriberFlags . PendingComputed )
309
286
) {
310
- dep . flags = depFlags & ~ SubscriberFlags . PendingComputed
311
- if ( current . nextSub !== undefined || current . prevSub !== undefined ) {
312
- prevLinks = { target : current , linked : prevLinks }
287
+ const depSubs = dep . subs !
288
+ if ( depSubs . nextSub !== undefined ) {
289
+ depSubs . prevSub = link
313
290
}
314
- ++ checkDepth
315
- current = dep . deps !
291
+ link = dep . deps !
292
+ ++ stack
316
293
continue
317
294
}
318
295
}
319
296
320
- if ( ( current = current . nextDep ! ) === undefined ) {
321
- return false
297
+ if ( ! dirty && link . nextDep !== undefined ) {
298
+ link = link . nextDep
299
+ continue
300
+ }
301
+
302
+ if ( stack ) {
303
+ let sub = link . sub as Computed
304
+ do {
305
+ -- stack
306
+ const subSubs = sub . subs !
307
+
308
+ if ( dirty ) {
309
+ if ( sub . update ( ) ) {
310
+ if ( ( link = subSubs . prevSub ! ) !== undefined ) {
311
+ subSubs . prevSub = undefined
312
+ shallowPropagate ( subSubs )
313
+ sub = link . sub as Computed
314
+ } else {
315
+ sub = subSubs . sub as Computed
316
+ }
317
+ continue
318
+ }
319
+ } else {
320
+ sub . flags &= ~ SubscriberFlags . PendingComputed
321
+ }
322
+
323
+ if ( ( link = subSubs . prevSub ! ) !== undefined ) {
324
+ subSubs . prevSub = undefined
325
+ if ( link . nextDep !== undefined ) {
326
+ link = link . nextDep
327
+ continue top
328
+ }
329
+ sub = link . sub as Computed
330
+ } else {
331
+ if ( ( link = subSubs . nextDep ! ) !== undefined ) {
332
+ continue top
333
+ }
334
+ sub = subSubs . sub as Computed
335
+ }
336
+
337
+ dirty = false
338
+ } while ( stack )
322
339
}
340
+
341
+ return dirty
323
342
} while ( true )
324
343
}
325
344
0 commit comments