]> Cypherpunks repositories - gostls13.git/commit
strings: speed-up replace for byteStringReplacer case
authorIlya Tocar <ilya.tocar@intel.com>
Mon, 26 Feb 2018 20:00:57 +0000 (14:00 -0600)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 2 Apr 2018 22:34:38 +0000 (22:34 +0000)
commitfd22542eaa02f73bdd1e74b5116165813fc3458b
treec2ef85578b12f0a464fa918ac24c7f2759d5971a
parentc0841ecd87a5a91cdd5e2c376d46230988a37ada
strings: speed-up replace for byteStringReplacer case

Use Count instead of loop to determine a number of replacements.
Also increment index instead of advancing slices, to avoid some extra stores.
Shows very significant speed-up on html benchmarks:

Escape-6          34.2µs ± 2%  20.8µs ± 2%  -39.06%  (p=0.000 n=10+10)
EscapeNone-6      7.04µs ± 1%  1.05µs ± 0%  -85.03%  (p=0.000 n=10+10)

On benchmarks in package strings results are still significant:

ByteStringMatch-6    1.59µs ± 2%    1.17µs ± 2%  -26.35%  (p=0.000 n=10+10)
HTMLEscapeNew-6       390ns ± 2%     337ns ± 2%  -13.62%  (p=0.000 n=10+10)
HTMLEscapeOld-6       621ns ± 2%     603ns ± 2%   -2.95%  (p=0.000 n=10+9)

Change-Id: Ibea3235b6e451ba72cd5db57716d17b917e72944
Reviewed-on: https://go-review.googlesource.com/97255
Run-TryBot: Ilya Tocar <ilya.tocar@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/strings/replace.go