mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-26 21:51:02 +03: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:
parent
af0602c343
commit
d4c6dd16b1
13 changed files with 322 additions and 123 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue