perf(parser): scan the input as bytes instead of runes

Assisted-by: GLM 5.3
This commit is contained in:
2026-09-17 23:11:50 +02:00
parent 3c8ac859c0
commit f1a757ec5c
3 changed files with 128 additions and 91 deletions
+3 -1
View File
@@ -110,7 +110,9 @@ func ParseContext(ctx context.Context, data []byte) (map[string]any, error) {
if !utf8.Valid(data) {
return nil, &SyntaxError{Line: 1, Msg: "input is not valid UTF-8"}
}
p := &parser{src: []rune(string(data)), line: 1, ctx: ctx}
// The parser scans data in place; it only reads the buffer, and every
// string it stores in the tree is copied out of it.
p := &parser{src: data, line: 1, ctx: ctx}
return p.parse()
}