mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
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:
@@ -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
|
||||
|
Reference in New Issue
Block a user