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