mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 06:00:25 +03:00
Improve rendering time
50% speedup. Fix #91 to run the benchmark: go test -test.run=NONE -bench=".*" -test.benchmem=true ./transform/ > new.txt to compare the results: /usr/local/go/misc/benchcmp baseline.txt new.txt Speedup and memory improvements benchmark old ns/op new ns/op delta BenchmarkChain 101219 50453 -50.15% BenchmarkTransform 51625 45531 -11.80% benchmark old allocs new allocs delta BenchmarkChain 222 103 -53.60% BenchmarkTransform 135 106 -21.48% benchmark old bytes new bytes delta BenchmarkChain 23919 10998 -54.02% BenchmarkTransform 11858 10665 -10.06%
This commit is contained in:
parent
f4cb8e1688
commit
9af47f07d3
9 changed files with 58 additions and 115 deletions
|
@ -1,29 +1,25 @@
|
|||
package transform
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
htmltran "code.google.com/p/go-html-transform/html/transform"
|
||||
"io"
|
||||
)
|
||||
|
||||
type chain struct {
|
||||
transformers []Transformer
|
||||
}
|
||||
type chain []*htmltran.Transform
|
||||
|
||||
func NewChain(trs ...Transformer) Transformer {
|
||||
return &chain{transformers: trs}
|
||||
func NewChain(trs ...*htmltran.Transform) chain {
|
||||
return trs
|
||||
}
|
||||
|
||||
func (c *chain) Apply(w io.Writer, r io.Reader) (err error) {
|
||||
in := r
|
||||
for _, tr := range c.transformers {
|
||||
out := new(bytes.Buffer)
|
||||
err = tr.Apply(out, in)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
in = bytes.NewBuffer(out.Bytes())
|
||||
|
||||
var tr *htmltran.Transformer
|
||||
|
||||
if tr, err = htmltran.NewFromReader(r); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = io.Copy(w, in)
|
||||
return
|
||||
tr.ApplyAll(*c...)
|
||||
|
||||
return tr.Render(w)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue