mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Use buffer pool in StripHTML
Allocates less memory: benchmark old ns/op new ns/op delta BenchmarkStripHTML 6572 6695 +1.87% benchmark old allocs new allocs delta BenchmarkStripHTML 5 4 -20.00% benchmark old bytes new bytes delta BenchmarkStripHTML 848 737 -13.09% Compared to 0.12: benchmark old ns/op new ns/op delta BenchmarkStripHTML 10210 6695 -34.43% benchmark old allocs new allocs delta BenchmarkStripHTML 6 4 -33.33% benchmark old bytes new bytes delta BenchmarkStripHTML 1456 737 -49.38%
This commit is contained in:
parent
5e34ae6199
commit
08219161dd
1 changed files with 5 additions and 3 deletions
|
@ -23,9 +23,9 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
"github.com/russross/blackfriday"
|
"github.com/russross/blackfriday"
|
||||||
"github.com/spf13/viper"
|
bp "github.com/spf13/hugo/bufferpool"
|
||||||
|
|
||||||
jww "github.com/spf13/jwalterweatherman"
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -81,7 +81,9 @@ func StripHTML(s string) string {
|
||||||
s = stripHTMLReplacer.Replace(s)
|
s = stripHTMLReplacer.Replace(s)
|
||||||
|
|
||||||
// Walk through the string removing all tags
|
// Walk through the string removing all tags
|
||||||
b := new(bytes.Buffer)
|
b := bp.GetBuffer()
|
||||||
|
defer bp.PutBuffer(b)
|
||||||
|
|
||||||
inTag := false
|
inTag := false
|
||||||
for _, r := range s {
|
for _, r := range s {
|
||||||
switch r {
|
switch r {
|
||||||
|
|
Loading…
Reference in a new issue