mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
fe4307f060
commit
d295174030
8 changed files with 305 additions and 294 deletions
|
|
@ -295,7 +295,7 @@ func walkrange(n *Node) {
|
|||
// if hv2 < utf8.RuneSelf {
|
||||
// hv1++
|
||||
// } else {
|
||||
// hv2, hv1 = charntorune(ha, hv1)
|
||||
// hv2, hv1 = decoderune(ha, hv1)
|
||||
// }
|
||||
// v2 = hv2
|
||||
// // original body
|
||||
|
|
@ -334,9 +334,9 @@ func walkrange(n *Node) {
|
|||
eif := nod(OAS2, nil, nil)
|
||||
nif.Rlist.Set1(eif)
|
||||
|
||||
// hv2, hv1 = charntorune(ha, hv1)
|
||||
// hv2, hv1 = decoderune(ha, hv1)
|
||||
eif.List.Set2(hv2, hv1)
|
||||
fn := syslook("charntorune")
|
||||
fn := syslook("decoderune")
|
||||
eif.Rlist.Set1(mkcall1(fn, fn.Type.Results(), nil, ha, hv1))
|
||||
|
||||
body = append(body, nif)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue