From 016f5903ed2116e5e334ec9ffacfbb3a9e8a7ea4 Mon Sep 17 00:00:00 2001 From: daishi Date: Wed, 16 Oct 2024 07:32:27 +0900 Subject: [PATCH] no need to add key in this data --- src/vanilla/utils/proxyMap.ts | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/vanilla/utils/proxyMap.ts b/src/vanilla/utils/proxyMap.ts index 48cb3d98..fb7eec2b 100644 --- a/src/vanilla/utils/proxyMap.ts +++ b/src/vanilla/utils/proxyMap.ts @@ -4,13 +4,13 @@ const { proxyStateMap, snapCache } = unstable_getInternalStates() const isProxy = (x: any) => proxyStateMap.has(x) type InternalProxyObject = Map & { - data: Array + data: Array index: number toJSON: () => Map } export function proxyMap(entries?: Iterable<[K, V]> | undefined | null) { - const initialData: Array = [] + const initialData: Array = [] let initialIndex = 0 const indexMap = new Map() @@ -33,7 +33,6 @@ export function proxyMap(entries?: Iterable<[K, V]> | undefined | null) { } for (const [key, value] of entries) { indexMap.set(key, initialIndex) - initialData[initialIndex++] = key initialData[initialIndex++] = value } } @@ -56,7 +55,7 @@ export function proxyMap(entries?: Iterable<[K, V]> | undefined | null) { this.index return undefined } - return this.data[index + 1] as V + return this.data[index] }, has(key: K) { const map = getMapForThis(this) @@ -73,13 +72,10 @@ export function proxyMap(entries?: Iterable<[K, V]> | undefined | null) { } const index = indexMap.get(key) if (index !== undefined) { - this.data[index + 1] = value + this.data[index] = value } else { - let nextIndex = this.index - indexMap.set(key, nextIndex) - this.data[nextIndex++] = key - this.data[nextIndex++] = value - this.index = nextIndex + indexMap.set(key, this.index) + this.data[this.index++] = value } return this }, @@ -92,7 +88,6 @@ export function proxyMap(entries?: Iterable<[K, V]> | undefined | null) { return false } delete this.data[index] - delete this.data[index + 1] indexMap.delete(key) return true }, @@ -107,13 +102,13 @@ export function proxyMap(entries?: Iterable<[K, V]> | undefined | null) { forEach(cb: (value: V, key: K, map: Map) => void) { const map = getMapForThis(this) map.forEach((index, key) => { - cb(this.data[index + 1] as V, key, this) + cb(this.data[index]!, key, this) }) }, *entries(): MapIterator<[K, V]> { const map = getMapForThis(this) for (const [key, index] of map) { - yield [key, this.data[index + 1]] as [K, V] + yield [key, this.data[index]!] } }, *keys(): IterableIterator { @@ -125,7 +120,7 @@ export function proxyMap(entries?: Iterable<[K, V]> | undefined | null) { *values(): IterableIterator { const map = getMapForThis(this) for (const index of map.values()) { - yield this.data[index + 1] as V + yield this.data[index]! } }, [Symbol.iterator]() {