Skip to content

Commit 250c37f

Browse files
committed
EachKey: do not allocate array if there is no need
1 parent 63af0e0 commit 250c37f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

parser.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,15 @@ func EachKey(data []byte, cb func(int, []byte, ValueType, error), paths ...[]str
422422
// for unescape: if there are no escape sequences, this is cheap; if there are, it is a
423423
// bit more expensive, but causes no allocations unless len(key) > unescapeStackBufSize
424424
var keyUnesc []byte
425-
var stackbuf [unescapeStackBufSize]byte
426425
if !keyEscaped {
427426
keyUnesc = key
428-
} else if ku, err := Unescape(key, stackbuf[:]); err != nil {
429-
return -1
430427
} else {
431-
keyUnesc = ku
428+
var stackbuf [unescapeStackBufSize]byte
429+
if ku, err := Unescape(key, stackbuf[:]); err != nil {
430+
return -1
431+
} else {
432+
keyUnesc = ku
433+
}
432434
}
433435

434436
if maxPath >= level {

0 commit comments

Comments
 (0)