]> Cypherpunks repositories - gostls13.git/commitdiff
text/template: avoid allocating a new common in copy
authortnclong <long.asyn@gmail.com>
Tue, 18 Jun 2019 14:07:30 +0000 (22:07 +0800)
committerDaniel Martí <mvdan@mvdan.cc>
Tue, 27 Aug 2019 16:56:26 +0000 (16:56 +0000)
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>
src/text/template/template.go

index 1135d819b99ae91d492b127e4e81159822e6481a..2c5ff013e39b73c42b10e80aa14125b4fe06aaaf 100644 (file)
@@ -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.