| // Copyright 2015 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| // TODO: implements short string optimization on non amd64 platforms |
| // and get rid of strings_amd64.go |
| // 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 { |
| return IndexByte(s, sep[0]) |
| hashsep, pow := hashStr(sep) |
| h = h*primeRK + uint32(s[i]) |
| if h == hashsep && s[:n] == sep { |
| for i := n; i < len(s); { |
| h -= pow * uint32(s[i-n]) |
| if h == hashsep && s[i-n:i] == sep { |