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