From 21e05b2e2713d2592197a993836c447fe970f0c9 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 20 Nov 2019 13:09:25 +0000 Subject: [PATCH] Reduce allocations --- util/data/data.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/util/data/data.go b/util/data/data.go index eb9fce16..5ad45a0e 100644 --- a/util/data/data.go +++ b/util/data/data.go @@ -93,6 +93,14 @@ func (d *Doc) UnmarshalJSON(data []byte) error { func (d *Doc) path(path ...string) (paths []string) { + l := len(path) + for _, p := range path { + l += strings.Count(p, ".") + l += strings.Count(p, "[") + } + + paths = make([]string, 0, l) + for _, p := range path { for j, i, o := 0, 0, false; i < len(p); i++ { switch {