From 79bc1f95cb2f328ecb994ea76629b725a2ed7faf Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Mon, 11 Oct 2021 12:56:27 +1100 Subject: [PATCH] Slight performance improvement to context.ChildContext --- pkg/yqlib/context.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/yqlib/context.go b/pkg/yqlib/context.go index fe1f372a..6be006f0 100644 --- a/pkg/yqlib/context.go +++ b/pkg/yqlib/context.go @@ -43,11 +43,14 @@ func (n *Context) SetVariable(name string, value *list.List) { } func (n *Context) ChildContext(results *list.List) Context { - clone := Context{} - err := copier.Copy(&clone, n) - if err != nil { - log.Error("Error cloning context :(") - panic(err) + clone := Context{DontAutoCreate: n.DontAutoCreate} + clone.Variables = make(map[string]*list.List) + if len(n.Variables) > 0 { + err := copier.Copy(&clone.Variables, n.Variables) + if err != nil { + log.Error("Error cloning context :(") + panic(err) + } } clone.MatchingNodes = results return clone