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
This commit is contained in:
Bjørn Erik Pedersen
2015-10-20 20:35:12 +02:00
parent 4ecf56b891
commit b08d9f26ae
4 changed files with 32 additions and 106 deletions

View File

@@ -204,6 +204,7 @@ func (p *Page) setSummary() {
p.Truncated = len(bytes.Trim(sections[1], " \n\r")) > 0
}
// TODO(bep) consider doing this once only
renderedHeader := p.renderBytes(header)
if len(p.contentShortCodes) > 0 {
tmpContentWithTokensReplaced, err :=