]> Cypherpunks repositories - gostls13.git/commit
fmt: use fewer allocations for %q string formatting
authorMartin Möhrmann <martisch@uos.de>
Sat, 5 Mar 2016 10:33:13 +0000 (11:33 +0100)
committerRob Pike <r@golang.org>
Sat, 5 Mar 2016 22:04:24 +0000 (22:04 +0000)
commit5763476f739ad4d6b122c2a7ae26a845ea020a7e
tree1c4c933492b1581355ea04c06b9498e1a549f701
parent00da3a6ec30bbad224d483a8d23a3b8a516c8e97
fmt: use fewer allocations for %q string formatting

Reuse the internal buffer and use append versions of
the strconv quote functions to avoid some allocations.

Add more tests.

name                  old time/op    new time/op    delta
SprintfQuoteString-2     486ns ± 2%     416ns ± 2%  -14.42%  (p=0.000 n=20+20)

name                  old allocs/op  new allocs/op  delta
SprintfQuoteString-2      4.00 ± 0%      2.00 ± 0%  -50.00%  (p=0.000 n=20+20)

Change-Id: I63795b51fd95c53c5993ec8e6e99b659941f9f54
Reviewed-on: https://go-review.googlesource.com/20251
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/fmt/fmt_test.go
src/fmt/format.go