mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-28 03:54:19 +00:00
Optimize replaceShortcodeTokens
We can of course skip reading the entire byte slice again and again. This was a slip in the original implementation; functionally the same, but is slightly faster, esp. for larger data sets with many shortcodes: ``` benchmark old ns/op new ns/op delta BenchmarkReplaceShortcodeTokens-4 15505 14753 -4.85% benchmark old allocs new allocs delta BenchmarkReplaceShortcodeTokens-4 1 1 +0.00% benchmark old bytes new bytes delta BenchmarkReplaceShortcodeTokens-4 3072 3072 +0.00% ```
This commit is contained in:
parent
8375995378
commit
455df10752
1 changed files with 1 additions and 1 deletions
|
@ -506,7 +506,7 @@ func replaceShortcodeTokens(source []byte, prefix string, replacements map[strin
|
||||||
|
|
||||||
// This and other cool slice tricks: https://github.com/golang/go/wiki/SliceTricks
|
// This and other cool slice tricks: https://github.com/golang/go/wiki/SliceTricks
|
||||||
source = append(source[:j], append(newVal, source[end:]...)...)
|
source = append(source[:j], append(newVal, source[end:]...)...)
|
||||||
|
start = j
|
||||||
k = bytes.Index(source[start:], pre)
|
k = bytes.Index(source[start:], pre)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue