Commit cfb8b18e authored by Dmitry Vyukov's avatar Dmitry Vyukov

strings: use LastIndexByte in LastIndex

Change-Id: I1add1b92f5c2688a99133d90bf9789d770fd9f05
Reviewed-on: https://go-review.googlesource.com/9503Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
parent 09edc5c6
......@@ -319,7 +319,7 @@ func hasPrefix(s, prefix string) bool {
return len(s) >= len(prefix) && s[0:len(prefix)] == prefix
}
// Variant of LastIndex from the strings package.
// LastIndexByte from the strings package.
func lastIndex(s string, sep byte) int {
for i := len(s) - 1; i >= 0; i-- {
if s[i] == sep {
......
......@@ -185,14 +185,7 @@ func LastIndex(s, sep string) int {
case n == 0:
return len(s)
case n == 1:
// special case worth making fast
c := sep[0]
for i := len(s) - 1; i >= 0; i-- {
if s[i] == c {
return i
}
}
return -1
return LastIndexByte(s, sep[0])
case n == len(s):
if sep == s {
return 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment