From 0ef14b51283ce5dbcef3403f1e729c6b6102f625 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 19 Sep 2024 04:36:15 -0400 Subject: [PATCH] chore: more `process_effect` tweaks (#13315) * consolidate more stuff * simpler * simplify * comment is unnecessary, this is the first time we read current_effect.first --- .../svelte/src/internal/client/constants.js | 3 +- .../svelte/src/internal/client/runtime.js | 33 +++++++------------ 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/packages/svelte/src/internal/client/constants.js b/packages/svelte/src/internal/client/constants.js index e5d39046891c..53df86126ac4 100644 --- a/packages/svelte/src/internal/client/constants.js +++ b/packages/svelte/src/internal/client/constants.js @@ -18,8 +18,7 @@ export const EFFECT_TRANSPARENT = 1 << 15; export const LEGACY_DERIVED_PROP = 1 << 16; export const INSPECT_EFFECT = 1 << 17; export const HEAD_EFFECT = 1 << 18; -export const EFFECT_QUEUED = 1 << 19; -export const EFFECT_HAS_DERIVED = 1 << 20; +export const EFFECT_HAS_DERIVED = 1 << 19; export const STATE_SYMBOL = Symbol('$state'); export const STATE_SYMBOL_METADATA = Symbol('$state metadata'); diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 2db62f8eeedb..93f8164ba3de 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -22,8 +22,7 @@ import { BLOCK_EFFECT, ROOT_EFFECT, LEGACY_DERIVED_PROP, - DISCONNECTED, - EFFECT_QUEUED + DISCONNECTED } from './constants.js'; import { flush_tasks } from './dom/task.js'; import { add_owner } from './dev/ownership.js'; @@ -512,8 +511,8 @@ function flush_queued_root_effects(root_effects) { for (var i = 0; i < length; i++) { var effect = root_effects[i]; - if ((effect.f & EFFECT_QUEUED) !== 0) { - effect.f ^= EFFECT_QUEUED; + if ((effect.f & CLEAN) === 0) { + effect.f ^= CLEAN; } /** @type {Effect[]} */ @@ -593,15 +592,10 @@ export function schedule_effect(signal) { effect = effect.parent; var flags = effect.f; - if ((flags & BRANCH_EFFECT) !== 0) { + if ((flags & (ROOT_EFFECT | BRANCH_EFFECT)) !== 0) { if ((flags & CLEAN) === 0) return; effect.f ^= CLEAN; } - - if ((flags & ROOT_EFFECT) !== 0) { - if ((flags & EFFECT_QUEUED) !== 0) return; - effect.f ^= EFFECT_QUEUED; - } } queued_root_effects.push(effect); @@ -624,23 +618,18 @@ function process_effects(effect, collected_effects) { main_loop: while (current_effect !== null) { var flags = current_effect.f; - var is_active = (flags & INERT) === 0; var is_branch = (flags & BRANCH_EFFECT) !== 0; - var is_clean = (flags & CLEAN) !== 0; - var child = current_effect.first; - - // Skip this branch if it's clean - if (is_active && (!is_branch || !is_clean)) { - if (is_branch) { - set_signal_status(current_effect, CLEAN); - } + var is_skippable_branch = is_branch && (flags & CLEAN) !== 0; + if (!is_skippable_branch && (flags & INERT) === 0) { if ((flags & RENDER_EFFECT) !== 0) { - if (!is_branch && check_dirtiness(current_effect)) { + if (is_branch) { + current_effect.f ^= CLEAN; + } else if (check_dirtiness(current_effect)) { update_effect(current_effect); } - // Child might have been mutated since running the effect or checking dirtiness - child = current_effect.first; + + var child = current_effect.first; if (child !== null) { current_effect = child;