refactor(capture): reuse JSON slice detachment (#17335)

This commit is contained in:
Vincent Koc
2026-12-06 10:28:39 +08:00
committed by GitHub
parent e8549a3579
commit e545408b84
+1 -8
View File
@@ -34,13 +34,6 @@ const detachSlice = (
return Buffer.from(text.slice(start, end), encoding).toString(encoding);
};
const detachAsciiSlice = (text: string, start: number, end: number): string => {
const length = end - start;
if (length === 0) return "";
if (length < 13) return text.slice(start, end);
return Buffer.from(text.slice(start, end), "latin1").toString("latin1");
};
const setOwnProperty = (
target: Record<string, unknown>,
key: string,
@@ -278,7 +271,7 @@ class StrictCaptureJsonParser {
this.#readDigits();
}
if (skip) return;
return new LosslessNumber(detachAsciiSlice(text, start, this.#pos));
return new LosslessNumber(detachSlice(text, start, this.#pos, true));
}
expectKeyword(word: "true" | "false" | "null"): void {