@@ -261,8 +261,10 @@ function linkNewDep(
261261function checkDirty ( current : Link ) : boolean {
262262 let prevLinks : OneWayLink < Link > | undefined
263263 let checkDepth = 0
264+ let dirty : boolean
264265
265266 top: do {
267+ dirty = false
266268 const dep = current . dep
267269
268270 if ( 'flags' in dep ) {
@@ -271,55 +273,64 @@ function checkDirty(current: Link): boolean {
271273 ( depFlags & ( SubscriberFlags . Computed | SubscriberFlags . Dirty ) ) ===
272274 ( SubscriberFlags . Computed | SubscriberFlags . Dirty )
273275 ) {
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 )
277280 }
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
304282 }
305283 } else if (
306284 ( depFlags &
307285 ( SubscriberFlags . Computed | SubscriberFlags . PendingComputed ) ) ===
308286 ( SubscriberFlags . Computed | SubscriberFlags . PendingComputed )
309287 ) {
310- dep . flags = depFlags & ~ SubscriberFlags . PendingComputed
311288 if ( current . nextSub !== undefined || current . prevSub !== undefined ) {
312289 prevLinks = { target : current , linked : prevLinks }
313290 }
314- ++ checkDepth
315291 current = dep . deps !
292+ ++ checkDepth
316293 continue
317294 }
318295 }
319296
320- if ( ( current = current . nextDep ! ) === undefined ) {
321- return false
297+ if ( ! dirty && current . nextDep !== undefined ) {
298+ current = current . nextDep
299+ continue
322300 }
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
323334 } while ( true )
324335}
325336
0 commit comments