Skip to content

Commit 4170e86

Browse files
committed
more efficient linking
1 parent ec12756 commit 4170e86

File tree

1 file changed

+15
-10
lines changed
  • packages/svelte/src/internal/client/dom/blocks

1 file changed

+15
-10
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,25 +314,35 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
314314

315315
prev = start.prev;
316316

317+
var a = matched[0];
318+
var b = matched[matched.length - 1];
319+
320+
link(a.prev, b.next);
321+
link(prev, a);
322+
link(b, start);
323+
317324
for (j = 0; j < matched.length; j += 1) {
318-
item = matched[j];
319-
move(item, prev, local_anchor);
320-
prev = item;
325+
move(matched[j], local_anchor);
321326
}
322327

323328
for (j = 0; j < stashed.length; j += 1) {
324329
seen.delete(stashed[j]);
325330
}
326331

327332
current = start;
333+
prev = b;
328334
i -= 1;
329335

330336
matched = [];
331337
stashed = [];
332338
} else {
333339
// more efficient to move earlier items to the back
334340
seen.delete(item);
335-
move(item, prev, current ? get_first_child(current) : anchor);
341+
move(item, current ? get_first_child(current) : anchor);
342+
343+
link(item.prev, item.next);
344+
link(item, prev.next);
345+
link(prev, item);
336346

337347
prev = item;
338348
}
@@ -470,10 +480,9 @@ function create_item(anchor, prev, next, value, key, index, render_fn, flags) {
470480

471481
/**
472482
* @param {import('#client').EachItem} item
473-
* @param {import('#client').EachItem | import('#client').EachState} prev
474483
* @param {Text | Element | Comment} anchor
475484
*/
476-
function move(item, prev, anchor) {
485+
function move(item, anchor) {
477486
var dom = item.e.dom;
478487

479488
if (dom !== null) {
@@ -485,10 +494,6 @@ function move(item, prev, anchor) {
485494
anchor.before(dom);
486495
}
487496
}
488-
489-
link(item.prev, item.next);
490-
link(item, prev.next);
491-
link(prev, item);
492497
}
493498

494499
/**

0 commit comments

Comments
 (0)