perf(sessions): reduce store clone allocations

This commit is contained in:
Peter Steinberger
2026-05-27 19:20:01 +01:00
parent f40275ce26
commit 99b27cde64

View File

@@ -196,10 +196,21 @@ function cloneJsonLikeValue<T>(value: T): T {
return value; return value;
} }
if (Array.isArray(value)) { if (Array.isArray(value)) {
return value.map((item) => cloneJsonLikeValue(item)) as T; const cloned = new Array(value.length);
for (let index = 0; index < value.length; index += 1) {
if (!(index in value)) {
continue;
}
cloned[index] = cloneJsonLikeValue(value[index]);
}
return cloned as T;
} }
const cloned: Record<string, unknown> = {}; const cloned: Record<string, unknown> = {};
for (const [key, child] of Object.entries(value as Record<string, unknown>)) { for (const key in value as Record<string, unknown>) {
if (!Object.prototype.hasOwnProperty.call(value, key)) {
continue;
}
const child = (value as Record<string, unknown>)[key];
if (child === undefined) { if (child === undefined) {
continue; continue;
} }