Commit 4a4f752c authored by tnclong's avatar tnclong Committed by Daniel Martí

text/template: avoid allocating a new common in copy

Template.New calls t.init, which allocates several items that
are immediately rewritten by copy, so avoid the call to New

Change-Id: I16c7cb001bbcd14cf547c1a2db2734a2f8214e7e
Reviewed-on: https://go-review.googlesource.com/c/go/+/182757
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarDaniel Martí <mvdan@mvdan.cc>
parent 32b9e568
...@@ -110,12 +110,13 @@ func (t *Template) Clone() (*Template, error) { ...@@ -110,12 +110,13 @@ func (t *Template) Clone() (*Template, error) {
// copy returns a shallow copy of t, with common set to the argument. // copy returns a shallow copy of t, with common set to the argument.
func (t *Template) copy(c *common) *Template { func (t *Template) copy(c *common) *Template {
nt := New(t.name) return &Template{
nt.Tree = t.Tree name: t.name,
nt.common = c Tree: t.Tree,
nt.leftDelim = t.leftDelim common: c,
nt.rightDelim = t.rightDelim leftDelim: t.leftDelim,
return nt rightDelim: t.rightDelim,
}
} }
// AddParseTree adds parse tree for template with given name and associates it with t. // AddParseTree adds parse tree for template with given name and associates it with t.
......
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