summaryrefslogtreecommitdiffstats
path: root/hugolib/shortcode.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-02-25 21:31:22 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-02-25 23:50:43 +0100
commit455df1075205d5fcda184410575e535e605c8f20 (patch)
treed8558f0eb2bb11613699ed165868e281d448af8f /hugolib/shortcode.go
parent83759953784367ef3ec16d494890167a2380353b (diff)
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% ```
Diffstat (limited to 'hugolib/shortcode.go')
-rw-r--r--hugolib/shortcode.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go
index 3ceef54ef..a1e0cc35d 100644
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -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
source = append(source[:j], append(newVal, source[end:]...)...)
-
+ start = j
k = bytes.Index(source[start:], pre)
}