From: Rob Pike Date: Mon, 30 Sep 2019 23:54:30 +0000 (+1000) Subject: text/template: further simplify building the vars list X-Git-Tag: go1.14beta1~912 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=27cf81e1b48efe6a6387f34c7114766c7b0d4d73;p=gostls13.git text/template: further simplify building the vars list Followup to https://golang.org/cl/197997 If you know the number of elements, you don't need append at all. Either use append to grow, or allocate and index. Here we choose number 2. Change-Id: Ic58637231789640ff7b293ece04a95a8de7ccf8f Reviewed-on: https://go-review.googlesource.com/c/go/+/198097 Reviewed-by: Ian Lance Taylor --- diff --git a/src/text/template/parse/node.go b/src/text/template/parse/node.go index 74552c293f..2f921be2ec 100644 --- a/src/text/template/parse/node.go +++ b/src/text/template/parse/node.go @@ -187,9 +187,9 @@ func (p *PipeNode) CopyPipe() *PipeNode { if p == nil { return p } - vars := make([]*VariableNode, 0, len(p.Decl)) - for _, d := range p.Decl { - vars = append(vars, d.Copy().(*VariableNode)) + vars := make([]*VariableNode, len(p.Decl)) + for i, d := range p.Decl { + vars[i] = d.Copy().(*VariableNode) } n := p.tr.newPipeline(p.Pos, p.Line, vars) n.IsAssign = p.IsAssign