From 27cf81e1b48efe6a6387f34c7114766c7b0d4d73 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 1 Oct 2019 09:54:30 +1000 Subject: [PATCH] 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 --- src/text/template/parse/node.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 -- 2.50.0