]> Cypherpunks repositories - gostls13.git/commit
runtime: speed up non-ASCII rune decoding
authorMartin Möhrmann <martisch@uos.de>
Fri, 2 Sep 2016 15:04:41 +0000 (17:04 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 17 Oct 2016 11:25:22 +0000 (11:25 +0000)
commitd2951740303587fc0c5d14cb5461e39b099e6695
tree97625f704787b103946792ad7475235744826c91
parentfe4307f0607dff7742d047b04df06e721aea7906
runtime: speed up non-ASCII rune decoding

Copies utf8 constants and EncodeRune implementation from unicode/utf8.

Adds a new decoderune implementation that is used by the compiler
in code generated for ranging over strings. It does not handle
ASCII runes since these are handled directly before calls to decoderune.

The DecodeRuneInString implementation from unicode/utf8 is not used
since it uses a lookup table that would increase the use of cpu caches.

Adds more tests that check decoding of valid and invalid utf8 sequences.

name                              old time/op  new time/op  delta
RuneIterate/range2/ASCII-4        7.45ns ± 2%  7.45ns ± 1%     ~     (p=0.634 n=16+16)
RuneIterate/range2/Japanese-4     53.5ns ± 1%  49.2ns ± 2%   -8.03%  (p=0.000 n=20+20)
RuneIterate/range2/MixedLength-4  46.3ns ± 1%  41.0ns ± 2%  -11.57%  (p=0.000 n=20+20)

new:
"".decoderune t=1 size=423 args=0x28 locals=0x0
old:
"".charntorune t=1 size=666 args=0x28 locals=0x0

Change-Id: I1df1fdb385bb9ea5e5e71b8818ea2bf5ce62de52
Reviewed-on: https://go-review.googlesource.com/28490
Run-TryBot: Martin Möhrmann <martisch@uos.de>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/builtin.go
src/cmd/compile/internal/gc/builtin/runtime.go
src/cmd/compile/internal/gc/range.go
src/runtime/rune.go [deleted file]
src/runtime/string.go
src/runtime/string_test.go
src/runtime/utf8.go [new file with mode: 0644]
src/unicode/utf8/utf8_test.go