Slight performance improvement to context.ChildContext

This commit is contained in:
Mike Farah 2021-10-11 12:56:27 +11:00
parent 4a4aae00af
commit 79bc1f95cb

View File

@ -43,12 +43,15 @@ func (n *Context) SetVariable(name string, value *list.List) {
} }
func (n *Context) ChildContext(results *list.List) Context { func (n *Context) ChildContext(results *list.List) Context {
clone := Context{} clone := Context{DontAutoCreate: n.DontAutoCreate}
err := copier.Copy(&clone, n) clone.Variables = make(map[string]*list.List)
if len(n.Variables) > 0 {
err := copier.Copy(&clone.Variables, n.Variables)
if err != nil { if err != nil {
log.Error("Error cloning context :(") log.Error("Error cloning context :(")
panic(err) panic(err)
} }
}
clone.MatchingNodes = results clone.MatchingNodes = results
return clone return clone
} }