aboutsummaryrefslogtreecommitdiff
path: root/src/text
diff options
context:
space:
mode:
authortnclong <long.asyn@gmail.com>2019-06-18 22:07:30 +0800
committerDaniel Martí <mvdan@mvdan.cc>2019-08-27 16:56:26 +0000
commit4a4f752c3812d18ffcaa06624de1a29d4e9ab056 (patch)
tree0ae8bbeb84043e82f048e551fc70e2118164d4da /src/text
parent32b9e568d8c28e63a8f1d93e69b57794350de159 (diff)
downloadgo-4a4f752c3812d18ffcaa06624de1a29d4e9ab056.tar.gz
go-4a4f752c3812d18ffcaa06624de1a29d4e9ab056.zip
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: Daniel Martí <mvdan@mvdan.cc>
Diffstat (limited to 'src/text')
-rw-r--r--src/text/template/template.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/text/template/template.go b/src/text/template/template.go
index 1135d819b9..2c5ff013e3 100644
--- a/src/text/template/template.go
+++ b/src/text/template/template.go
@@ -110,12 +110,13 @@ func (t *Template) Clone() (*Template, error) {
// copy returns a shallow copy of t, with common set to the argument.
func (t *Template) copy(c *common) *Template {
- nt := New(t.name)
- nt.Tree = t.Tree
- nt.common = c
- nt.leftDelim = t.leftDelim
- nt.rightDelim = t.rightDelim
- return nt
+ return &Template{
+ name: t.name,
+ Tree: t.Tree,
+ common: c,
+ leftDelim: t.leftDelim,
+ rightDelim: t.rightDelim,
+ }
}
// AddParseTree adds parse tree for template with given name and associates it with t.