From 52f7afe855ddb5ee3c503e7ad08faf07954350aa Mon Sep 17 00:00:00 2001 From: Michael Sweeney Date: Fri, 11 Oct 2024 19:31:26 -0700 Subject: [PATCH] changed nextIndex to use local var --- src/vanilla/utils/proxyMap-indexMap.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/vanilla/utils/proxyMap-indexMap.ts b/src/vanilla/utils/proxyMap-indexMap.ts index 5391995a..3485f088 100644 --- a/src/vanilla/utils/proxyMap-indexMap.ts +++ b/src/vanilla/utils/proxyMap-indexMap.ts @@ -5,7 +5,6 @@ const isProxy = (x: any) => proxyStateMap.has(x) type InternalProxyObject = Map & { data: Array<[K, V | undefined]> - nextIndex: number size: number toJSON: () => Map } @@ -14,8 +13,9 @@ export function proxyMap(entries?: Iterable<[K, V]> | undefined | null) { const data: Array<[K, V]> = new Array(1000).fill(undefined) const indexMap = new Map() const emptyIndexes: number[] = [] + let nextIndex = 0 - if (entries !== null && typeof entries !== 'undefined') { + if (entries) { if (typeof entries[Symbol.iterator] !== 'function') { throw new TypeError( 'proxyMap:\n\tinitial state must be iterable\n\t\ttip: structure should be [[key, value]]', @@ -25,13 +25,12 @@ export function proxyMap(entries?: Iterable<[K, V]> | undefined | null) { const key = maybeProxify(k) const value = maybeProxify(v) indexMap.set(key, data.length) - data.push([key, value]) + data[nextIndex++] = [key, value] } } const vObject: InternalProxyObject = { data, - nextIndex: data.length, get size() { return indexMap.size }, @@ -65,7 +64,7 @@ export function proxyMap(entries?: Iterable<[K, V]> | undefined | null) { const v = maybeProxify(value) let index = indexMap.get(k) if (index === undefined) { - index = emptyIndexes.length ? emptyIndexes.pop()! : this.nextIndex++ + index = emptyIndexes.length ? emptyIndexes.pop()! : nextIndex++ indexMap.set(k, index) } const pair = this.data[index] @@ -99,7 +98,7 @@ export function proxyMap(entries?: Iterable<[K, V]> | undefined | null) { indexMap.clear() this.data.splice(0) emptyIndexes.splice(0) - this.nextIndex = 0 + nextIndex = 0 }, forEach(cb: (value: V, key: K, map: Map) => void) { indexMap.forEach((index) => { @@ -137,7 +136,6 @@ export function proxyMap(entries?: Iterable<[K, V]> | undefined | null) { Object.defineProperties(proxiedObject, { size: { enumerable: false }, data: { enumerable: false }, - nextIndex: { enumerable: false }, toJSON: { enumerable: false }, })