Make replaceShortcodeTokens rewrite the input slice
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 20 Oct 2015 18:35:12 +0000 (20:35 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 17 Nov 2015 17:24:17 +0000 (18:24 +0100)
commitb08d9f26ae00b6c55f615ad6b8fc36608e684204
tree9f91dd35147a008423653d9bf540dafde52ab8a7
parent4ecf56b891339e7a463280ab65e0eeebb8e5e206
Make replaceShortcodeTokens rewrite the input slice

Currently a `[]byte` copy is returned. In most cases this is the safe thing to do, but we should just modify/grow the slice as needed.

This is faster and consumes less memory:

```
benchmark                             old ns/op     new ns/op     delta
BenchmarkReplaceShortcodeTokens-4     7350          4419          -39.88%

benchmark                             old allocs     new allocs     delta
BenchmarkReplaceShortcodeTokens-4     5              1              -80.00%

benchmark                             old bytes     new bytes     delta
BenchmarkReplaceShortcodeTokens-4     4816          1152          -76.08%
```

This commit is aso a small spring cleaning of duplicated code in the different `PageConvert` methods.

Fixes #1516
hugolib/handler_page.go
hugolib/page.go
hugolib/shortcode.go
hugolib/shortcode_test.go