Skip to content

Commit 17281c3

Browse files
authored
Revert "chore: remove deopts and refactor code for controlled optimizations (…" (#11043)
This reverts commit 3ece9cd.
1 parent 3ece9cd commit 17281c3

File tree

2 files changed

+19
-48
lines changed

2 files changed

+19
-48
lines changed

packages/svelte/src/internal/client/dom/blocks/each.js

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ import {
1717
branch,
1818
effect,
1919
pause_effect,
20-
get_out_transitions,
21-
resume_effect,
2220
pause_effects,
23-
destroy_effects
21+
resume_effect
2422
} from '../../reactivity/effects.js';
2523
import { source, mutable_source, set } from '../../reactivity/sources.js';
2624
import { is_array, is_frozen, map_get, map_set } from '../../utils.js';
@@ -246,17 +244,9 @@ function reconcile_indexed_array(array, state, anchor, render_fn, flags) {
246244
effects.push(a_items[i].e);
247245
}
248246

249-
var transitions = get_out_transitions(effects);
250-
var items = state.items;
251-
252-
if (transitions.length === 0) {
253-
destroy_effects(effects);
254-
items.length = b;
255-
} else {
256-
pause_effects(effects, transitions, () => {
257-
items.length = b;
258-
});
259-
}
247+
pause_effects(effects, () => {
248+
state.items.length = b;
249+
});
260250
}
261251
}
262252

@@ -431,16 +421,11 @@ function reconcile_tracked_array(array, state, anchor, render_fn, flags, keys) {
431421
});
432422
}
433423

434-
var transitions = get_out_transitions(to_destroy);
435-
436-
if (transitions.length === 0) {
437-
destroy_effects(to_destroy);
424+
// TODO: would be good to avoid this closure in the case where we have no
425+
// transitions at all. It would make it far more JIT friendly in the hot cases.
426+
pause_effects(to_destroy, () => {
438427
state.items = b_items;
439-
} else {
440-
pause_effects(to_destroy, transitions, () => {
441-
state.items = b_items;
442-
});
443-
}
428+
});
444429
}
445430

446431
/**

packages/svelte/src/internal/client/reactivity/effects.js

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -313,38 +313,23 @@ export function pause_effect(effect, callback = noop) {
313313
* Pause multiple effects simultaneously, and coordinate their
314314
* subsequent destruction. Used in each blocks
315315
* @param {import('#client').Effect[]} effects
316-
* @returns {import('#client').TransitionManager[]}
316+
* @param {() => void} callback
317317
*/
318-
export function get_out_transitions(effects) {
318+
export function pause_effects(effects, callback = noop) {
319319
/** @type {import('#client').TransitionManager[]} */
320320
var transitions = [];
321+
var length = effects.length;
321322

322-
for (var i = 0; i < effects.length; i++) {
323+
for (var i = 0; i < length; i++) {
323324
pause_children(effects[i], transitions, true);
324325
}
325326

326-
return transitions;
327-
}
328-
329-
/**
330-
* @param {import('#client').Effect[]} effects
331-
*/
332-
export function destroy_effects(effects) {
333-
for (var i = 0; i < effects.length; i++) {
334-
destroy_effect(effects[i]);
335-
}
336-
}
337-
338-
/**
339-
* Pause multiple effects simultaneously, and coordinate their
340-
* subsequent destruction. Used in each blocks
341-
* @param {import('#client').Effect[]} effects
342-
* @param {import('#client').TransitionManager[]} transitions
343-
* @param {() => void} callback
344-
*/
345-
export function pause_effects(effects, transitions, callback = noop) {
327+
// TODO: would be good to avoid this closure in the case where we have no
328+
// transitions at all. It would make it far more JIT friendly in the hot cases.
346329
out(transitions, () => {
347-
destroy_effects(effects);
330+
for (var i = 0; i < length; i++) {
331+
destroy_effect(effects[i]);
332+
}
348333
callback();
349334
});
350335
}
@@ -385,12 +370,13 @@ function pause_children(effect, transitions, local) {
385370
var child = effect.first;
386371

387372
while (child !== null) {
373+
var sibling = child.next;
388374
var transparent = (child.f & IS_ELSEIF) !== 0 || (child.f & BRANCH_EFFECT) !== 0;
389375
// TODO we don't need to call pause_children recursively with a linked list in place
390376
// it's slightly more involved though as we have to account for `transparent` changing
391377
// through the tree.
392378
pause_children(child, transitions, transparent ? local : false);
393-
child = child.next;
379+
child = sibling;
394380
}
395381
}
396382

0 commit comments

Comments
 (0)