]> Cypherpunks repositories - gostls13.git/commitdiff
text/template: further simplify building the vars list
authorRob Pike <r@golang.org>
Mon, 30 Sep 2019 23:54:30 +0000 (09:54 +1000)
committerRob Pike <r@golang.org>
Tue, 1 Oct 2019 00:00:02 +0000 (00:00 +0000)
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 <iant@golang.org>
src/text/template/parse/node.go

index 74552c293f70fec1b9c7d1fa92712076430f1553..2f921be2ecf92ee4f2a5aa23fbb70b68e8e43eed 100644 (file)
@@ -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