From 250c37f3d676ecab57726eed7d6bd48a48cee1c2 Mon Sep 17 00:00:00 2001 From: Alexandr Karasev Date: Tue, 16 Jun 2020 20:19:44 +0200 Subject: [PATCH] EachKey: do not allocate array if there is no need --- parser.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/parser.go b/parser.go index 26d1cd8..854a430 100644 --- a/parser.go +++ b/parser.go @@ -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 {