Skip to content

Commit

Permalink
Merge pull request #208 from xsandr/each-array-memory-optimization
Browse files Browse the repository at this point in the history
EachKey: do not allocate array if there is no need
  • Loading branch information
buger committed Nov 24, 2020
2 parents 71a899e + 250c37f commit 1239415
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions parser.go
Expand Up @@ -414,13 +414,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 1239415

Please sign in to comment.