diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2014-10-06 15:10:51 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2014-10-06 15:10:51 -0700 |
| commit | 4731c382f6875863dc27f33088f53bce8f82c620 (patch) | |
| tree | cf9e197b4cddee800e83cf1f984c190d02f886f3 /src/strings/strings.go | |
| parent | f8f95590d946bb4619599f909b6facf14f9bed03 (diff) | |
| download | go-4731c382f6875863dc27f33088f53bce8f82c620.tar.xz | |
strings: use fast path for IndexRune
Noticed while reviewing https://golang.org/cl/147690043/
I'd never seen anybody use IndexRune before, and
unsurprisingly it doesn't use the other fast paths in the
strings/bytes packages. IndexByte uses assembly.
Also, less code this way.
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/147700043
Diffstat (limited to 'src/strings/strings.go')
| -rw-r--r-- | src/strings/strings.go | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/src/strings/strings.go b/src/strings/strings.go index 1b9df2e757..27d384983e 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -225,13 +225,8 @@ func LastIndex(s, sep string) int { // r, or -1 if rune is not present in s. func IndexRune(s string, r rune) int { switch { - case r < 0x80: - b := byte(r) - for i := 0; i < len(s); i++ { - if s[i] == b { - return i - } - } + case r < utf8.RuneSelf: + return IndexByte(s, byte(r)) default: for i, c := range s { if c == r { |
