Files
SnowLuma/.pnpm-store/v11/files/17/e68acb37a9eea7561e30eeafa13f93ad89ce2bd4892c7d882a637f7c1e71da98d240eb067b5f89e014efe1e673bb0ae480cf661d8a992905ad0a6c1f9c3943
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

45 lines
1.4 KiB
Plaintext

// Lazy materialization for the lanes===1 fast path. Backed by a
// Float64Array (stride 2: start, size, …); VirtualItems are constructed on
// first indexed read and cached. Saves the per-item object allocation at
// large list counts where most items are never visible.
import type { VirtualItem } from './index'
type Key = number | string | bigint
export function createLazyMeasurementsView(
count: number,
flat: Float64Array,
getItemKey: (i: number) => Key,
): Array<VirtualItem> {
const cache: Array<VirtualItem | undefined> = new Array(count)
return new Proxy(cache as any, {
get(target, prop, receiver) {
if (typeof prop === 'string') {
// Cheap digit-prefix sniff before number coerce.
const c = prop.charCodeAt(0)
if (c >= 48 && c <= 57) {
const i = +prop
if (Number.isInteger(i) && i >= 0 && i < count) {
let v = target[i]
if (!v) {
const s = flat[i * 2]!
v = target[i] = {
index: i,
key: getItemKey(i),
start: s,
size: flat[i * 2 + 1]!,
end: s + flat[i * 2 + 1]!,
lane: 0,
}
}
return v
}
}
if (prop === 'length') return count
}
return Reflect.get(target, prop, receiver)
},
}) as Array<VirtualItem>
}