Skip to content

Commit ec12756

Browse files
committed
microoptimisations
1 parent 593631d commit ec12756

File tree

1 file changed

+17
-12
lines changed
  • packages/svelte/src/internal/client/dom/blocks

1 file changed

+17
-12
lines changed

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,11 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
256256
/** @type {import('#client').EachItem | undefined} */
257257
var item;
258258

259+
/** @type {number} */
260+
var i;
261+
259262
if (is_animated) {
260-
for (let i = 0; i < length; i += 1) {
263+
for (i = 0; i < length; i += 1) {
261264
value = array[i];
262265
key = get_key(value, i);
263266
item = items.get(key);
@@ -269,7 +272,7 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
269272
}
270273
}
271274

272-
for (let i = 0; i < length; i += 1) {
275+
for (i = 0; i < length; i += 1) {
273276
value = array[i];
274277
key = get_key(value, i);
275278
item = items.get(key);
@@ -305,29 +308,31 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
305308
if (seen.has(item)) {
306309
if (matched.length < stashed.length) {
307310
// more efficient to move later items to the front
308-
prev = stashed[0].prev;
309-
const a = get_first_child(stashed[0]);
311+
var start = stashed[0];
312+
var local_anchor = get_first_child(start);
313+
var j;
314+
315+
prev = start.prev;
310316

311-
for (item of matched) {
312-
move(item, prev, a);
317+
for (j = 0; j < matched.length; j += 1) {
318+
item = matched[j];
319+
move(item, prev, local_anchor);
313320
prev = item;
314321
}
315322

316-
for (item of stashed) {
317-
seen.delete(item);
323+
for (j = 0; j < stashed.length; j += 1) {
324+
seen.delete(stashed[j]);
318325
}
319326

320-
current = stashed[0];
327+
current = start;
321328
i -= 1;
322329

323330
matched = [];
324331
stashed = [];
325332
} else {
326333
// more efficient to move earlier items to the back
327-
const a = current ? get_first_child(current) : anchor;
328-
329334
seen.delete(item);
330-
move(item, prev, a);
335+
move(item, prev, current ? get_first_child(current) : anchor);
331336

332337
prev = item;
333338
}

0 commit comments

Comments
 (0)