]> Cypherpunks repositories - gostls13.git/commitdiff
strings: remove a couple of redundant tests
authorRobert Griesemer <gri@golang.org>
Thu, 25 Feb 2010 18:02:39 +0000 (10:02 -0800)
committerRobert Griesemer <gri@golang.org>
Thu, 25 Feb 2010 18:02:39 +0000 (10:02 -0800)
(per suggestion from Heresy.Mc@gmail.com)

R=rsc
CC=golang-dev
https://golang.org/cl/223052

src/pkg/strings/strings.go

index 48d4f0e96a3f411335ecd99f557371706db7f965..eb2b7e09c61cec5358b942ffa11c8ae10b295f72 100644 (file)
@@ -65,8 +65,9 @@ func Index(s, sep string) int {
                }
                return -1
        }
+       // n > 1
        for i := 0; i+n <= len(s); i++ {
-               if s[i] == c && (n == 1 || s[i:i+n] == sep) {
+               if s[i] == c && s[i:i+n] == sep {
                        return i
                }
        }
@@ -89,8 +90,9 @@ func LastIndex(s, sep string) int {
                }
                return -1
        }
+       // n > 1
        for i := len(s) - n; i >= 0; i-- {
-               if s[i] == c && (n == 1 || s[i:i+n] == sep) {
+               if s[i] == c && s[i:i+n] == sep {
                        return i
                }
        }