Commit 27cf81e1 authored by Rob Pike's avatar Rob Pike

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/+/198097Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent e76b9e89
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment