chore: more `process_effect` tweaks (#13315)

* consolidate more stuff

* simpler

* simplify

* comment is unnecessary, this is the first time we read current_effect.first
pull/13319/head
Rich Harris 1 day ago committed by GitHub
parent 5d56c592ff
commit 0ef14b5128
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -18,8 +18,7 @@ export const EFFECT_TRANSPARENT = 1 << 15;
export const LEGACY_DERIVED_PROP = 1 << 16; export const LEGACY_DERIVED_PROP = 1 << 16;
export const INSPECT_EFFECT = 1 << 17; export const INSPECT_EFFECT = 1 << 17;
export const HEAD_EFFECT = 1 << 18; export const HEAD_EFFECT = 1 << 18;
export const EFFECT_QUEUED = 1 << 19; export const EFFECT_HAS_DERIVED = 1 << 19;
export const EFFECT_HAS_DERIVED = 1 << 20;
export const STATE_SYMBOL = Symbol('$state'); export const STATE_SYMBOL = Symbol('$state');
export const STATE_SYMBOL_METADATA = Symbol('$state metadata'); export const STATE_SYMBOL_METADATA = Symbol('$state metadata');

@ -22,8 +22,7 @@ import {
BLOCK_EFFECT, BLOCK_EFFECT,
ROOT_EFFECT, ROOT_EFFECT,
LEGACY_DERIVED_PROP, LEGACY_DERIVED_PROP,
DISCONNECTED, DISCONNECTED
EFFECT_QUEUED
} from './constants.js'; } from './constants.js';
import { flush_tasks } from './dom/task.js'; import { flush_tasks } from './dom/task.js';
import { add_owner } from './dev/ownership.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++) { for (var i = 0; i < length; i++) {
var effect = root_effects[i]; var effect = root_effects[i];
if ((effect.f & EFFECT_QUEUED) !== 0) { if ((effect.f & CLEAN) === 0) {
effect.f ^= EFFECT_QUEUED; effect.f ^= CLEAN;
} }
/** @type {Effect[]} */ /** @type {Effect[]} */
@ -593,15 +592,10 @@ export function schedule_effect(signal) {
effect = effect.parent; effect = effect.parent;
var flags = effect.f; var flags = effect.f;
if ((flags & BRANCH_EFFECT) !== 0) { if ((flags & (ROOT_EFFECT | BRANCH_EFFECT)) !== 0) {
if ((flags & CLEAN) === 0) return; if ((flags & CLEAN) === 0) return;
effect.f ^= CLEAN; effect.f ^= CLEAN;
} }
if ((flags & ROOT_EFFECT) !== 0) {
if ((flags & EFFECT_QUEUED) !== 0) return;
effect.f ^= EFFECT_QUEUED;
}
} }
queued_root_effects.push(effect); queued_root_effects.push(effect);
@ -624,23 +618,18 @@ function process_effects(effect, collected_effects) {
main_loop: while (current_effect !== null) { main_loop: while (current_effect !== null) {
var flags = current_effect.f; var flags = current_effect.f;
var is_active = (flags & INERT) === 0;
var is_branch = (flags & BRANCH_EFFECT) !== 0; var is_branch = (flags & BRANCH_EFFECT) !== 0;
var is_clean = (flags & CLEAN) !== 0; var is_skippable_branch = is_branch && (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);
}
if (!is_skippable_branch && (flags & INERT) === 0) {
if ((flags & RENDER_EFFECT) !== 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); 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) { if (child !== null) {
current_effect = child; current_effect = child;

Loading…
Cancel
Save