aboutsummaryrefslogtreecommitdiffstats
path: root/func.go
diff options
context:
space:
mode:
authorFumitoshi Ukai <fumitoshi.ukai@gmail.com>2015-06-19 15:46:21 +0900
committerFumitoshi Ukai <fumitoshi.ukai@gmail.com>2015-06-19 15:46:21 +0900
commit77411fb4bdcab6222a51ef1a4a0f625b7f4a4523 (patch)
tree1feb5e408d621b5ddba50388ca465b6b1984d14b /func.go
parentce14acbe573bdf2853e67ea418940e835c07409b (diff)
downloadandroid_build_kati-77411fb4bdcab6222a51ef1a4a0f625b7f4a4523.tar.gz
android_build_kati-77411fb4bdcab6222a51ef1a4a0f625b7f4a4523.tar.bz2
android_build_kati-77411fb4bdcab6222a51ef1a4a0f625b7f4a4523.zip
reduce allocation in funcPatsubst
benchmark old ns/op new ns/op delta BenchmarkFuncPatsubst 2030 1102 -45.71% benchmark old allocs new allocs delta BenchmarkFuncPatsubst 9 1 -88.89% benchmark old bytes new bytes delta BenchmarkFuncPatsubst 297 32 -89.23%
Diffstat (limited to 'func.go')
-rw-r--r--func.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/func.go b/func.go
index 62e9af4..f6c3b41 100644
--- a/func.go
+++ b/func.go
@@ -182,10 +182,18 @@ func (f *funcPatsubst) Eval(w io.Writer, ev *Evaluator) {
pat := fargs[0]
repl := fargs[1]
ws := newWordScanner(fargs[2])
- sw := ssvWriter{w: w}
+ space := false
for ws.Scan() {
- t := substPatternBytes(pat, repl, ws.Bytes())
- sw.Write(t)
+ if space {
+ writeByte(w, ' ')
+ }
+ pre, subst, post := substPatternBytes(pat, repl, ws.Bytes())
+ w.Write(pre)
+ if subst != nil {
+ w.Write(subst)
+ w.Write(post)
+ }
+ space = true
}
freeBuf(abuf)
addStats("funcbody", "patsubst", t)