Skip to content

Commit

Permalink
chore: more process_effect tweaks (#13315)
Browse files Browse the repository at this point in the history
* consolidate more stuff

* simpler

* simplify

* comment is unnecessary, this is the first time we read current_effect.first
  • Loading branch information
Rich-Harris authored Sep 19, 2024
1 parent 5d56c59 commit 0ef14b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
3 changes: 1 addition & 2 deletions packages/svelte/src/internal/client/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
33 changes: 11 additions & 22 deletions packages/svelte/src/internal/client/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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[]} */
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 0ef14b5

Please sign in to comment.