c2047754c3
Compiler changes: * Change map assignment to use mapassign and assign value directly. * Change string iteration to use decoderune, faster for ASCII strings. * Change makeslice to take int, and use makeslice64 for larger values. * Add new noverflow field to hmap struct used for maps. Unresolved problems, to be fixed later: * Commented out test in go/types/sizes_test.go that doesn't compile. * Commented out reflect.TestStructOf test for padding after zero-sized field. Reviewed-on: https://go-review.googlesource.com/35231 gotools/: Updates for Go 1.8rc1. * Makefile.am (go_cmd_go_files): Add bug.go. (s-zdefaultcc): Write defaultPkgConfig. * Makefile.in: Rebuild. From-SVN: r244456
42 lines
760 B
Go
42 lines
760 B
Go
// 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 bytes
|
|
|
|
// TODO: implements short string optimization on non amd64 platforms
|
|
// and get rid of bytes_amd64.go
|
|
|
|
// 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 []byte) int {
|
|
n := len(sep)
|
|
if n == 0 {
|
|
return 0
|
|
}
|
|
if n > len(s) {
|
|
return -1
|
|
}
|
|
c := sep[0]
|
|
if n == 1 {
|
|
return IndexByte(s, c)
|
|
}
|
|
i := 0
|
|
t := s[:len(s)-n+1]
|
|
for i < len(t) {
|
|
if t[i] != c {
|
|
o := IndexByte(t[i:], c)
|
|
if o < 0 {
|
|
break
|
|
}
|
|
i += o
|
|
}
|
|
if Equal(s[i:i+n], sep) {
|
|
return i
|
|
}
|
|
i++
|
|
}
|
|
return -1
|
|
}
|