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
This commit is contained in:
Bjørn Erik Pedersen
2019-04-23 12:33:51 +02:00
parent 4756ec3cd8
commit 69a56420ae
3 changed files with 129 additions and 5 deletions

View File

@@ -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