diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-10-24 13:45:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-24 13:45:30 +0200 |
commit | a10b2cd372798c4e4b862f0ec03010d2aea2ff1e (patch) | |
tree | f768c420aac0008e4d118709e13fda278a7588c5 /helpers/path.go | |
parent | dffd7da07c3fb198acfa6c4664b53132c4cabe55 (diff) | |
download | hugo-a10b2cd372798c4e4b862f0ec03010d2aea2ff1e.tar.gz hugo-a10b2cd372798c4e4b862f0ec03010d2aea2ff1e.zip |
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
Diffstat (limited to 'helpers/path.go')
-rw-r--r-- | helpers/path.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/helpers/path.go b/helpers/path.go index b8f642470..cf49858ee 100644 --- a/helpers/path.go +++ b/helpers/path.go @@ -75,16 +75,16 @@ var fpb filepathBridge // It does so by creating a Unicode-sanitized string, with the spaces replaced, // whilst preserving the original casing of the string. // E.g. Social Media -> Social-Media -func MakePath(s string) string { - return UnicodeSanitize(strings.Replace(strings.TrimSpace(s), " ", "-", -1)) +func (p *PathSpec) MakePath(s string) string { + return p.UnicodeSanitize(strings.Replace(strings.TrimSpace(s), " ", "-", -1)) } // MakePathSanitized creates a Unicode-sanitized string, with the spaces replaced -func MakePathSanitized(s string) string { - if viper.GetBool("DisablePathToLower") { - return MakePath(s) +func (p *PathSpec) MakePathSanitized(s string) string { + if p.disablePathToLower { + return p.MakePath(s) } - return strings.ToLower(MakePath(s)) + return strings.ToLower(p.MakePath(s)) } // MakeTitle converts the path given to a suitable title, trimming whitespace @@ -110,7 +110,7 @@ func ishex(c rune) bool { // a predefined set of special Unicode characters. // If RemovePathAccents configuration flag is enabled, Uniccode accents // are also removed. -func UnicodeSanitize(s string) string { +func (p *PathSpec) UnicodeSanitize(s string) string { source := []rune(s) target := make([]rune, 0, len(source)) @@ -124,7 +124,7 @@ func UnicodeSanitize(s string) string { var result string - if viper.GetBool("RemovePathAccents") { + if p.removePathAccents { // remove accents - see https://blog.golang.org/normalization t := transform.Chain(norm.NFD, transform.RemoveFunc(isMn), norm.NFC) result, _, _ = transform.String(t, string(target)) |