diff options
Diffstat (limited to 'src/strings/strings_amd64.go')
| -rw-r--r-- | src/strings/strings_amd64.go | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/strings/strings_amd64.go b/src/strings/strings_amd64.go index 23a98d5945..8f6ac1de74 100644 --- a/src/strings/strings_amd64.go +++ b/src/strings/strings_amd64.go @@ -21,27 +21,27 @@ func init() { } } -// Index returns the index of the first instance of sep in s, or -1 if sep is not present in s. -func Index(s, sep string) int { - n := len(sep) +// Index returns the index of the first instance of substr in s, or -1 if substr is not present in s. +func Index(s, substr string) int { + n := len(substr) switch { case n == 0: return 0 case n == 1: - return IndexByte(s, sep[0]) + return IndexByte(s, substr[0]) case n == len(s): - if sep == s { + if substr == s { return 0 } return -1 case n > len(s): return -1 case n <= shortStringLen: - // Use brute force when s and sep both are small + // Use brute force when s and substr both are small if len(s) <= 64 { - return indexShortStr(s, sep) + return indexShortStr(s, substr) } - c := sep[0] + c := substr[0] i := 0 t := s[:len(s)-n+1] fails := 0 @@ -55,7 +55,7 @@ func Index(s, sep string) int { } i += o } - if s[i:i+n] == sep { + if s[i:i+n] == substr { return i } fails++ @@ -64,7 +64,7 @@ func Index(s, sep string) int { // Too many means more that 1 error per 8 characters. // Allow some errors in the beginning. if fails > (i+16)/8 { - r := indexShortStr(s[i:], sep) + r := indexShortStr(s[i:], substr) if r >= 0 { return r + i } @@ -74,12 +74,12 @@ func Index(s, sep string) int { return -1 } // Rabin-Karp search - hashsep, pow := hashStr(sep) + hashss, pow := hashStr(substr) var h uint32 for i := 0; i < n; i++ { h = h*primeRK + uint32(s[i]) } - if h == hashsep && s[:n] == sep { + if h == hashss && s[:n] == substr { return 0 } for i := n; i < len(s); { @@ -87,7 +87,7 @@ func Index(s, sep string) int { h += uint32(s[i]) h -= pow * uint32(s[i-n]) i++ - if h == hashsep && s[i-n:i] == sep { + if h == hashss && s[i-n:i] == substr { return i - n } } |
