Skip to content

Commit 05fef7b

Browse files
committed
Optimized ParseString (compiler wasn't inlining parseStringAsBytes)
1 parent d02e4bd commit 05fef7b

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

parser.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,10 @@ func ParseBoolean(b []byte) (bool, error) {
459459
}
460460
}
461461

462-
// ParseString parses a String ValueType into a Go []byte (the main parsing work is unescaping the JSON string)
463-
func parseStringAsBytes(b []byte) ([]byte, error) {
464-
var stackbuf [unescapeStackBufSize]byte // stack-allocated array for allocation-free unescaping of small strings (hopefully; the Go compiler might just always kick stackbuf[:] into the heap)
465-
return Unescape(b, stackbuf[:])
466-
}
467-
468462
// ParseString parses a String ValueType into a Go string (the main parsing work is unescaping the JSON string)
469463
func ParseString(b []byte) (string, error) {
470-
if bU, err := parseStringAsBytes(b); err != nil {
464+
var stackbuf [unescapeStackBufSize]byte // stack-allocated array for allocation-free unescaping of small strings
465+
if bU, err := Unescape(b, stackbuf[:]); err != nil {
471466
return "", nil
472467
} else {
473468
return string(bU), nil

0 commit comments

Comments
 (0)