1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
11 // indexShortStr returns the index of the first instance of sep in s,
12 // or -1 if sep is not present in s.
13 // indexShortStr requires 2 <= len(sep) <= shortStringLen
14 func indexShortStr(s
, sep
string) int // ../runtime/asm_$GOARCH.s
16 // supportsVX reports whether the vector facility is available.
17 // indexShortStr must not be called if the vector facility is not
19 func supportsVX() bool // ../runtime/asm_s390x.s
21 var shortStringLen
= -1
29 // Index returns the index of the first instance of sep in s, or -1 if sep is not present in s.
30 func Index(s
, sep
string) int {
36 return IndexByte(s
, sep
[0])
44 case n
<= shortStringLen
:
45 // Use brute force when s and sep both are small
47 return indexShortStr(s
, sep
)
55 // IndexByte skips 16/32 bytes per iteration,
56 // so it's faster than indexShortStr.
57 o
:= IndexByte(t
[i
:], c
)
68 // Switch to indexShortStr when IndexByte produces too many false positives.
69 // Too many means more that 1 error per 8 characters.
70 // Allow some errors in the beginning.
72 r
:= indexShortStr(s
[i
:], sep
)
82 hashsep
, pow
:= hashStr(sep
)
84 for i
:= 0; i
< n
; i
++ {
85 h
= h
*primeRK
+ uint32(s
[i
])
87 if h
== hashsep
&& s
[:n
] == sep
{
90 for i
:= n
; i
< len(s
); {
93 h
-= pow
* uint32(s
[i
-n
])
95 if h
== hashsep
&& s
[i
-n
:i
] == sep
{