diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-08-05 17:27:16 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-08-05 17:27:16 +0200 |
commit | a6b1eb1e9150aa5c1c86fe7424cc4167d6f59a5a (patch) | |
tree | 28e2ab67284ad0b946477b3c6c7865e45d55e796 | |
parent | 27110133ffca05feae2e11a9ff28a9a00f613350 (diff) |
transform: Reduce allocation in the benchmark itself
-rw-r--r-- | transform/chain_test.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/transform/chain_test.go b/transform/chain_test.go index 7b770ed67..ae5f06a2d 100644 --- a/transform/chain_test.go +++ b/transform/chain_test.go @@ -19,6 +19,7 @@ import ( "strings" "testing" + bp "github.com/gohugoio/hugo/bufferpool" "github.com/gohugoio/hugo/helpers" "github.com/stretchr/testify/assert" ) @@ -235,16 +236,24 @@ func TestNewEmptyTransforms(t *testing.T) { type errorf func(string, ...interface{}) func applyWithPath(ef errorf, tr chain, tests []test, path string) { + out := bp.GetBuffer() + defer bp.PutBuffer(out) + + in := bp.GetBuffer() + defer bp.PutBuffer(in) + for _, test := range tests { - out := new(bytes.Buffer) var err error - err = tr.Apply(out, strings.NewReader(test.content), []byte(path)) + in.WriteString(test.content) + err = tr.Apply(out, in, []byte(path)) if err != nil { ef("Unexpected error: %s", err) } - if test.expected != string(out.Bytes()) { - ef("Expected:\n%s\nGot:\n%s", test.expected, string(out.Bytes())) + if test.expected != out.String() { + ef("Expected:\n%s\nGot:\n%s", test.expected, out.String()) } + out.Reset() + in.Reset() } } |