From a44b766d8ecf8b92706bd78d54e86cccdc4b0553 Mon Sep 17 00:00:00 2001 From: Fumitoshi Ukai Date: Fri, 19 Jun 2015 11:07:07 +0900 Subject: reduce allocation in funcStrip benchmark old ns/op new ns/op delta BenchmarkFuncStrip 468 334 -28.63% benchmark old allocs new allocs delta BenchmarkFuncStrip 1 0 -100.00% benchmark old bytes new bytes delta BenchmarkFuncStrip 32 0 -100.00% --- func.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'func.go') diff --git a/func.go b/func.go index 37a9ea9..9dc48c1 100644 --- a/func.go +++ b/func.go @@ -195,9 +195,13 @@ func (f *funcStrip) Eval(w io.Writer, ev *Evaluator) { abuf := newBuf() f.args[1].Eval(abuf, ev) ws := newWordScanner(abuf.Bytes()) - sw := ssvWriter{w: w} + space := false for ws.Scan() { - sw.Write(ws.Bytes()) + if space { + writeByte(w, ' ') + } + w.Write(ws.Bytes()) + space = true } freeBuf(abuf) } -- cgit v1.2.3