diff options
| author | Keith Randall <khr@golang.org> | 2018-03-04 09:47:47 -0800 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2018-03-04 19:49:44 +0000 |
| commit | ee58eccc565c0871d3f16fd702fd8649a3fb61ea (patch) | |
| tree | 837073b78954dc987cf575ff478faf6fdb8afb0e /src/strings/strings_generic.go | |
| parent | f6332bb84ad87e958290ae23b29a2b13a41ee2a2 (diff) | |
| download | go-ee58eccc565c0871d3f16fd702fd8649a3fb61ea.tar.xz | |
internal/bytealg: move short string Index implementations into bytealg
Also move the arm64 CountByte implementation while we're here.
Fixes #19792
Change-Id: I1e0fdf1e03e3135af84150a2703b58dad1b0d57e
Reviewed-on: https://go-review.googlesource.com/98518
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/strings/strings_generic.go')
| -rw-r--r-- | src/strings/strings_generic.go | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/src/strings/strings_generic.go b/src/strings/strings_generic.go deleted file mode 100644 index ac3b8dce85..0000000000 --- a/src/strings/strings_generic.go +++ /dev/null @@ -1,55 +0,0 @@ -// 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. - -// +build !amd64,!s390x - -package strings - -// 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 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, substr[0]) - case n == len(s): - if substr == s { - return 0 - } - return -1 - case n > len(s): - return -1 - } - c := substr[0] - i := 0 - t := s[:len(s)-n+1] - fails := 0 - for i < len(t) { - if t[i] != c { - o := IndexByte(t[i:], c) - if o < 0 { - return -1 - } - i += o - } - if s[i:i+n] == substr { - return i - } - i++ - fails++ - if fails >= 4+i>>4 && i < len(t) { - // See comment in ../bytes/bytes_generic.go. - j := indexRabinKarp(s[i:], substr) - if j < 0 { - return -1 - } - return i + j - } - } - return -1 -} |
