perf(go): size quoted build-info decoding to the field (#15445)

* perf(go): size quoted build-info decoding to the field

* perf(go): size one decode buffer from the quoted field's extent
This commit is contained in:
morluto authored and GitHub committed 2026-12-01 06:42:34 +00:00
1 parent 4d183de844
commit ebffd53a89
1 file changed
+13 -1
+13 -1
View File
@@ -14,6 +14,16 @@ const escapes = new Map([
['"', 34],
]);
/** Index of the closing quote or line end of the double-quoted field at the start of `input`. */
const quotedFieldEnd = (input: string): number => {
for (let index = 1; index < input.length; index += 1) {
const character = input[index];
if (character === "\\") index += 1;
else if (character === '"' || character === "\n") return index;
}
return input.length;
};
const quoted = (input: string): { value: string; end: number } | null => {
if (input.startsWith("`")) {
const end = input.indexOf("`", 1);
@@ -22,7 +32,9 @@ const quoted = (input: string): { value: string; end: number } | null => {
: { value: input.slice(1, end).replace(/\r/g, ""), end: end + 1 };
}
if (!input.startsWith('"')) return null;
const output = Buffer.alloc(input.length * 3);
// Each source UTF-16 unit decodes to at most three bytes, so the field's own
// extent bounds the output; the rest of the line does not.
const output = Buffer.alloc(quotedFieldEnd(input) * 3);
let length = 0;
for (let index = 1; index < input.length;) {
const character = input[index];