Skip to content

Commit

Permalink
fixup! perf(core): optimize memory allocation when reconcilling lists
Browse files Browse the repository at this point in the history
  • Loading branch information
pkozlowski-opensource committed Oct 17, 2023
1 parent 4b3a64c commit 3e1ab2c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/core/src/render3/list_reconciliation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function initLiveItemsInTheFuture<T>(
*/
export class UniqueValueMultiKeyMap<K, V> {
private kvMap = new Map<K, V>();
private _vMap: Map<V, V>|undefined;
private _vMap: Map<V, V>|undefined = undefined;

private get vMap() {
return this._vMap ??= new Map<V, V>();
Expand Down Expand Up @@ -307,9 +307,11 @@ export class UniqueValueMultiKeyMap<K, V> {
forEach(cb: (v: V, k: K) => void) {
for (let [key, value] of this.kvMap) {
cb(value, key);
while (this.vMap.has(value)) {
value = this.vMap.get(value)!;
cb(value, key);
if (this._vMap !== undefined) {
while (this.vMap.has(value)) {
value = this.vMap.get(value)!;
cb(value, key);
}
}
}
}
Expand Down

0 comments on commit 3e1ab2c

Please sign in to comment.