mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 22:21:07 +03:00
Avoid reading from Viper for path and URL funcs
The gain, given the "real sites benchmark" below, is obvious: ``` benchmark old ns/op new ns/op delta BenchmarkHugo-4 14497594101 13084156335 -9.75% benchmark old allocs new allocs delta BenchmarkHugo-4 57404335 48282002 -15.89% benchmark old bytes new bytes delta BenchmarkHugo-4 9933505624 9721984424 -2.13% ``` Fixes #2495
This commit is contained in:
parent
dffd7da07c
commit
a10b2cd372
26 changed files with 348 additions and 90 deletions
|
@ -24,6 +24,10 @@ import (
|
|||
)
|
||||
|
||||
func TestURLize(t *testing.T) {
|
||||
initCommonTestConfig()
|
||||
|
||||
p := NewPathSpecFromConfig(viper.GetViper())
|
||||
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
|
@ -37,7 +41,7 @@ func TestURLize(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, test := range tests {
|
||||
output := URLize(test.input)
|
||||
output := p.URLize(test.input)
|
||||
if output != test.expected {
|
||||
t.Errorf("Expected %#v, got %#v\n", test.expected, output)
|
||||
}
|
||||
|
@ -83,7 +87,8 @@ func doTestAbsURL(t *testing.T, defaultInSubDir, addLanguage, multilingual bool,
|
|||
|
||||
for _, test := range tests {
|
||||
viper.Set("BaseURL", test.baseURL)
|
||||
output := AbsURL(test.input, addLanguage)
|
||||
p := NewPathSpecFromConfig(viper.GetViper())
|
||||
output := p.AbsURL(test.input, addLanguage)
|
||||
expected := test.expected
|
||||
if multilingual && addLanguage {
|
||||
if !defaultInSubDir && lang == "en" {
|
||||
|
@ -159,8 +164,9 @@ func doTestRelURL(t *testing.T, defaultInSubDir, addLanguage, multilingual bool,
|
|||
for i, test := range tests {
|
||||
viper.Set("BaseURL", test.baseURL)
|
||||
viper.Set("canonifyURLs", test.canonify)
|
||||
p := NewPathSpecFromConfig(viper.GetViper())
|
||||
|
||||
output := RelURL(test.input, addLanguage)
|
||||
output := p.RelURL(test.input, addLanguage)
|
||||
|
||||
expected := test.expected
|
||||
if multilingual && addLanguage {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue