mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-17 21:01:26 +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:
@@ -1,6 +1,7 @@
|
||||
package hugolib
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -42,6 +43,8 @@ type sitesBuilder struct {
|
||||
Fs *hugofs.Fs
|
||||
T testing.TB
|
||||
|
||||
*require.Assertions
|
||||
|
||||
logger *loggers.Logger
|
||||
|
||||
dumper litter.Options
|
||||
@@ -88,7 +91,7 @@ func newTestSitesBuilder(t testing.TB) *sitesBuilder {
|
||||
Separator: " ",
|
||||
}
|
||||
|
||||
return &sitesBuilder{T: t, Fs: fs, configFormat: "toml", dumper: litterOptions}
|
||||
return &sitesBuilder{T: t, Assertions: require.New(t), Fs: fs, configFormat: "toml", dumper: litterOptions}
|
||||
}
|
||||
|
||||
func createTempDir(prefix string) (string, func(), error) {
|
||||
@@ -260,6 +263,21 @@ lag = "lag"
|
||||
|
||||
}
|
||||
|
||||
func (s *sitesBuilder) WithSunset(in string) {
|
||||
// Write a real image into one of the bundle above.
|
||||
src, err := os.Open(filepath.FromSlash("testdata/sunset.jpg"))
|
||||
s.NoError(err)
|
||||
|
||||
out, err := s.Fs.Source.Create(filepath.FromSlash(in))
|
||||
s.NoError(err)
|
||||
|
||||
_, err = io.Copy(out, src)
|
||||
s.NoError(err)
|
||||
|
||||
out.Close()
|
||||
src.Close()
|
||||
}
|
||||
|
||||
func (s *sitesBuilder) WithContent(filenameContent ...string) *sitesBuilder {
|
||||
s.contentFilePairs = append(s.contentFilePairs, filenameContent...)
|
||||
return s
|
||||
|
Reference in New Issue
Block a user