1
0
mirror of https://github.com/golang/go synced 2024-11-18 11:04:42 -07:00

strings: use LastIndexByte in LastIndex

Change-Id: I1add1b92f5c2688a99133d90bf9789d770fd9f05
Reviewed-on: https://go-review.googlesource.com/9503
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Dmitry Vyukov 2015-04-30 10:16:23 +03:00
parent 09edc5c6ac
commit cfb8b18e75
2 changed files with 2 additions and 9 deletions

View File

@ -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 {

View File

@ -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