From 69a56420aec5bf5abb846701d4a5ec67fe060d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 23 Apr 2019 12:33:51 +0200 Subject: 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 --- tpl/tplimpl/template.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tpl') 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 -- cgit v1.2.3