]> Cypherpunks repositories - gostls13.git/commitdiff
strings: use LastIndexByte in LastIndex
authorDmitry Vyukov <dvyukov@google.com>
Thu, 30 Apr 2015 07:16:23 +0000 (10:16 +0300)
committerDmitry Vyukov <dvyukov@google.com>
Thu, 30 Apr 2015 08:33:29 +0000 (08:33 +0000)
Change-Id: I1add1b92f5c2688a99133d90bf9789d770fd9f05
Reviewed-on: https://go-review.googlesource.com/9503
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/os/file_plan9.go
src/strings/strings.go

index 132594eede9c6d34b9f1b305d116f6e82c8b6db8..6850884d58d1b698f0a898959981d01cfd83b487 100644 (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 {
index 7b8a6b536b5d85f060f48433bd68b416ac15da39..567a3c5bfae0acd306299ed0ebb4a97098081d4e 100644 (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