| // 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. |
| // indexShortStr returns the index of the first instance of c in s, or -1 if c is not present in s. |
| // indexShortStr requires 2 <= len(c) <= shortStringLen |
| func indexShortStr(s, c string) int // ../runtime/asm_$GOARCH.s |
| func supportAVX2() bool // ../runtime/asm_$GOARCH.s |
| // 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]) |
| case n <= shortStringLen: |
| return indexShortStr(s, sep) |
| 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 { |