Skip to content

Commit 1239415

Browse files
authored
Merge pull request #208 from xsandr/each-array-memory-optimization
EachKey: do not allocate array if there is no need
2 parents 71a899e + 250c37f commit 1239415

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
@@ -414,13 +414,15 @@ func EachKey(data []byte, cb func(int, []byte, ValueType, error), paths ...[]str
414414
// for unescape: if there are no escape sequences, this is cheap; if there are, it is a
415415
// bit more expensive, but causes no allocations unless len(key) > unescapeStackBufSize
416416
var keyUnesc []byte
417-
var stackbuf [unescapeStackBufSize]byte
418417
if !keyEscaped {
419418
keyUnesc = key
420-
} else if ku, err := Unescape(key, stackbuf[:]); err != nil {
421-
return -1
422419
} else {
423-
keyUnesc = ku
420+
var stackbuf [unescapeStackBufSize]byte
421+
if ku, err := Unescape(key, stackbuf[:]); err != nil {
422+
return -1
423+
} else {
424+
keyUnesc = ku
425+
}
424426
}
425427

426428
if maxPath >= level {

0 commit comments

Comments
 (0)