mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
add bytes.IndexByte; common case we can make fast later.
also pick off the special case in strings.Index. don't want strings.IndexByte because the call site will very rarely need to allocate and we can handle the test in the code itself. bytes.IndexByte can avoid a common allocation. R=rsc CC=golang-dev https://golang.org/cl/156091
This commit is contained in:
parent
1a8ebcc4b8
commit
8c1a627e5c
4 changed files with 96 additions and 17 deletions
|
|
@ -46,6 +46,14 @@ var indexTests = []IndexTest{
|
|||
IndexTest{"foo", "", 0},
|
||||
IndexTest{"foo", "o", 1},
|
||||
IndexTest{"abcABCabc", "A", 3},
|
||||
// cases with one byte strings - test special case in Index()
|
||||
IndexTest{"", "a", -1},
|
||||
IndexTest{"x", "a", -1},
|
||||
IndexTest{"x", "x", 0},
|
||||
IndexTest{"abc", "a", 0},
|
||||
IndexTest{"abc", "b", 1},
|
||||
IndexTest{"abc", "c", 2},
|
||||
IndexTest{"abc", "x", -1},
|
||||
}
|
||||
|
||||
var lastIndexTests = []IndexTest{
|
||||
|
|
@ -54,6 +62,7 @@ var lastIndexTests = []IndexTest{
|
|||
IndexTest{"", "foo", -1},
|
||||
IndexTest{"fo", "foo", -1},
|
||||
IndexTest{"foo", "foo", 0},
|
||||
IndexTest{"foo", "f", 0},
|
||||
IndexTest{"oofofoofooo", "f", 7},
|
||||
IndexTest{"oofofoofooo", "foo", 7},
|
||||
IndexTest{"barfoobarfoo", "foo", 9},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue