1 // Copyright 2015 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.
5 // -build !amd64,!s390x,!arm64
9 // Index returns the index of the first instance of sep in s, or -1 if sep is not present in s.
10 func Index(s
, sep
[]byte) int {
16 return IndexByte(s
, sep
[0])
31 o
:= IndexByte(t
[i
:], c
)
37 if Equal(s
[i
:i
+n
], sep
) {
42 if fails
>= 4+i
>>4 && i
< len(t
) {
43 // Give up on IndexByte, it isn't skipping ahead
44 // far enough to be better than Rabin-Karp.
45 // Experiments (using IndexPeriodic) suggest
46 // the cutover is about 16 byte skips.
47 // TODO: if large prefixes of sep are matching
48 // we should cutover at even larger average skips,
49 // because Equal becomes that much more expensive.
50 // This code does not take that effect into account.
51 j
:= indexRabinKarp(s
[i
:], sep
)
61 // Count counts the number of non-overlapping instances of sep in s.
62 // If sep is an empty slice, Count returns 1 + the number of UTF-8-encoded code points in s.
63 func Count(s
, sep
[]byte) int {
64 return countGeneric(s
, sep
)