Skip to content

Commit 2297ebc

Browse files
Merge pull request #21323 from johanrd/perf/destroyable-remove-swap-pop
Perf: destroyable remove swap pop (render)
2 parents 3a55a1e + 945ef21 commit 2297ebc

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

packages/@glimmer/destroyable/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ function remove<T extends object>(collection: OneOrMany<T>, item: T, message: st
6767

6868
if (isBrandedArray(collection) && collection.length > 1) {
6969
let index = collection.indexOf(item);
70-
collection.splice(index, 1);
70+
let lastIndex = collection.length - 1;
71+
if (index !== lastIndex) {
72+
collection[index] = collection[lastIndex] as T;
73+
}
74+
collection.length = lastIndex;
7175
return collection;
7276
} else {
7377
return null;

0 commit comments

Comments
 (0)