chore: simplify process_effects (#15270)

* chore: simplify process_effects

* return effects
pull/15274/head
Rich Harris 7 months ago committed by GitHub
parent 280d8c74cc
commit 73220b8667
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -679,10 +679,7 @@ function flush_queued_root_effects(root_effects) {
effect.f ^= CLEAN; effect.f ^= CLEAN;
} }
/** @type {Effect[]} */ var collected_effects = process_effects(effect);
var collected_effects = [];
process_effects(effect, collected_effects);
flush_queued_effects(collected_effects); flush_queued_effects(collected_effects);
} }
} finally { } finally {
@ -783,13 +780,14 @@ export function schedule_effect(signal) {
* effects to be flushed. * effects to be flushed.
* *
* @param {Effect} effect * @param {Effect} effect
* @param {Effect[]} collected_effects * @returns {Effect[]}
* @returns {void}
*/ */
function process_effects(effect, collected_effects) { function process_effects(effect) {
var current_effect = effect.first; /** @type {Effect[]} */
var effects = []; var effects = [];
var current_effect = effect.first;
main_loop: while (current_effect !== null) { main_loop: while (current_effect !== null) {
var flags = current_effect.f; var flags = current_effect.f;
var is_branch = (flags & BRANCH_EFFECT) !== 0; var is_branch = (flags & BRANCH_EFFECT) !== 0;
@ -797,8 +795,9 @@ function process_effects(effect, collected_effects) {
var sibling = current_effect.next; var sibling = current_effect.next;
if (!is_skippable_branch && (flags & INERT) === 0) { if (!is_skippable_branch && (flags & INERT) === 0) {
if ((flags & RENDER_EFFECT) !== 0) { if ((flags & EFFECT) !== 0) {
if (is_branch) { effects.push(current_effect);
} else if (is_branch) {
current_effect.f ^= CLEAN; current_effect.f ^= CLEAN;
} else { } else {
// Ensure we set the effect to be the active reaction // Ensure we set the effect to be the active reaction
@ -823,9 +822,6 @@ function process_effects(effect, collected_effects) {
current_effect = child; current_effect = child;
continue; continue;
} }
} else if ((flags & EFFECT) !== 0) {
effects.push(current_effect);
}
} }
if (sibling === null) { if (sibling === null) {
@ -847,13 +843,7 @@ function process_effects(effect, collected_effects) {
current_effect = sibling; current_effect = sibling;
} }
// We might be dealing with many effects here, far more than can be spread into return effects;
// an array push call (callstack overflow). So let's deal with each effect in a loop.
for (var i = 0; i < effects.length; i++) {
child = effects[i];
collected_effects.push(child);
process_effects(child, collected_effects);
}
} }
/** /**

Loading…
Cancel
Save