Skip to content

Commit

Permalink
EachKey: do not allocate array if there is no need
Browse files Browse the repository at this point in the history
  • Loading branch information
xsandr committed Jun 16, 2020
1 parent 63af0e0 commit 250c37f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions parser.go
Expand Up @@ -422,13 +422,15 @@ func EachKey(data []byte, cb func(int, []byte, ValueType, error), paths ...[]str
// for unescape: if there are no escape sequences, this is cheap; if there are, it is a
// bit more expensive, but causes no allocations unless len(key) > unescapeStackBufSize
var keyUnesc []byte
var stackbuf [unescapeStackBufSize]byte
if !keyEscaped {
keyUnesc = key
} else if ku, err := Unescape(key, stackbuf[:]); err != nil {
return -1
} else {
keyUnesc = ku
var stackbuf [unescapeStackBufSize]byte
if ku, err := Unescape(key, stackbuf[:]); err != nil {
return -1
} else {
keyUnesc = ku
}
}

if maxPath >= level {
Expand Down

0 comments on commit 250c37f

Please sign in to comment.