Skip to content

Commit

Permalink
strings: use fast path for IndexRune
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bradfitz authored and wheatman committed Jun 25, 2018
1 parent 2bb836e commit 03a2ec9
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/strings/strings.go
Expand Up @@ -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 {
Expand Down

0 comments on commit 03a2ec9

Please sign in to comment.