diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-04-23 12:33:51 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-04-24 12:37:57 +0200 |
commit | 69a56420aec5bf5abb846701d4a5ec67fe060d96 (patch) | |
tree | 8b411312f114c3757d699b92250870f313b21989 /tpl | |
parent | 4756ec3cd8ef998f889619fe11be70cc900e2b75 (diff) |
hugolib: Avoid recloning of shortcode templates
```bash
benchmark old ns/op new ns/op delta
BenchmarkSiteNew/Bundle_with_image-4 14572242 14382188 -1.30%
BenchmarkSiteNew/Bundle_with_JSON_file-4 13683922 13738196 +0.40%
BenchmarkSiteNew/Multiple_languages-4 41912231 25192494 -39.89%
benchmark old allocs new allocs delta
BenchmarkSiteNew/Bundle_with_image-4 57496 57493 -0.01%
BenchmarkSiteNew/Bundle_with_JSON_file-4 57492 57501 +0.02%
BenchmarkSiteNew/Multiple_languages-4 242422 118809 -50.99%
benchmark old bytes new bytes delta
BenchmarkSiteNew/Bundle_with_image-4 3845077 3844065 -0.03%
BenchmarkSiteNew/Bundle_with_JSON_file-4 3627442 3627798 +0.01%
BenchmarkSiteNew/Multiple_languages-4 13963502 7543885 -45.97%
```
Fixes #5890
Diffstat (limited to 'tpl')
-rw-r--r-- | tpl/tplimpl/template.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/tpl/tplimpl/template.go b/tpl/tplimpl/template.go index c1fad3068..f0d3066e2 100644 --- a/tpl/tplimpl/template.go +++ b/tpl/tplimpl/template.go @@ -252,12 +252,12 @@ func (t *htmlTemplates) LookupVariant(name string, variants tpl.TemplateVariants return t.handler.LookupVariant(name, variants) } -func (t *templateHandler) cloneTemplate(in interface{}) tpl.Template { +func (t *templateHandler) lookupTemplate(in interface{}) tpl.Template { switch templ := in.(type) { case *texttemplate.Template: - return texttemplate.Must(templ.Clone()) + return t.text.lookup(templ.Name()) case *template.Template: - return template.Must(templ.Clone()) + return t.html.lookup(templ.Name()) } panic(fmt.Sprintf("%T is not a template", in)) @@ -294,7 +294,7 @@ func (t *templateHandler) clone(d *deps.Deps) *templateHandler { variantsc[i] = shortcodeVariant{ info: variant.info, variants: variant.variants, - templ: t.cloneTemplate(variant.templ), + templ: c.lookupTemplate(variant.templ), } } other.variants = variantsc |