mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-19 21:21:39 +02:00
tpl: Add templates.Current
This commit also * Unexport all internal state in TemplateInfo. * Make the dispatcher keys used for passing context.Context into uint8 from string to save memory allocations. Co-authored-by: Joe Mooring <joe@mooring.com> Updates #13571
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package tplimpl_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
@@ -840,3 +842,42 @@ All.
|
||||
|
||||
b.AssertLogContains("Duplicate content path")
|
||||
}
|
||||
|
||||
func BenchmarkExecuteWithContext(b *testing.B) {
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
disableKinds = ["taxonomy", "term", "home"]
|
||||
-- layouts/all.html --
|
||||
{{ .Title }}|
|
||||
{{ partial "p1.html" . }}
|
||||
-- layouts/_partials/p1.html --
|
||||
p1.
|
||||
{{ partial "p2.html" . }}
|
||||
{{ partial "p2.html" . }}
|
||||
{{ partial "p3.html" . }}
|
||||
{{ partial "p2.html" . }}
|
||||
{{ partial "p2.html" . }}
|
||||
{{ partial "p2.html" . }}
|
||||
{{ partial "p3.html" . }}
|
||||
-- layouts/_partials/p2.html --
|
||||
{{ partial "p3.html" . }}
|
||||
-- layouts/_partials/p3.html --
|
||||
p3
|
||||
-- content/p1.md --
|
||||
`
|
||||
|
||||
bb := hugolib.Test(b, files)
|
||||
|
||||
store := bb.H.TemplateStore
|
||||
|
||||
ti := store.LookupByPath("/all.html")
|
||||
bb.Assert(ti, qt.Not(qt.IsNil))
|
||||
p := bb.H.Sites[0].RegularPages()[0]
|
||||
bb.Assert(p, qt.Not(qt.IsNil))
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
err := store.ExecuteWithContext(context.Background(), ti, io.Discard, p)
|
||||
bb.Assert(err, qt.IsNil)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user