]> Cypherpunks.ru repositories - gostls13.git/commitdiff
all: prefer strings.IndexByte over strings.Index
authorMarvin Stenger <marvin.stenger94@gmail.com>
Thu, 21 Sep 2017 17:01:27 +0000 (19:01 +0200)
committerIan Lance Taylor <iant@golang.org>
Mon, 25 Sep 2017 17:35:41 +0000 (17:35 +0000)
strings.IndexByte was introduced in go1.2 and it can be used
effectively wherever the second argument to strings.Index is
exactly one byte long.

This avoids generating unnecessary string symbols and saves
a few calls to strings.Index.

Change-Id: I1ab5edb7c4ee9058084cfa57cbcc267c2597e793
Reviewed-on: https://go-review.googlesource.com/65930
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
55 files changed:
src/cmd/api/goapi.go
src/cmd/cgo/gcc.go
src/cmd/cgo/godefs.go
src/cmd/compile/fmt_test.go
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/gc/noder.go
src/cmd/compile/internal/gc/plive.go
src/cmd/compile/internal/ssa/gen/rulegen.go
src/cmd/compile/internal/syntax/nodes_test.go
src/cmd/dist/main.go
src/cmd/doc/main.go
src/cmd/fix/fix.go
src/cmd/fix/typecheck.go
src/cmd/go/go_test.go
src/cmd/go/internal/base/base.go
src/cmd/go/internal/cmdflag/flag.go
src/cmd/go/internal/get/get.go
src/cmd/go/internal/get/vcs.go
src/cmd/go/internal/load/match_test.go
src/cmd/go/internal/load/pkg.go
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/deadcode.go
src/cmd/link/internal/ld/go.go
src/cmd/link/internal/ld/ld.go
src/cmd/vet/asmdecl.go
src/cmd/vet/print.go
src/cmd/vet/structtag.go
src/crypto/x509/pem_decrypt.go
src/crypto/x509/root_darwin_arm_gen.go
src/debug/gosym/symtab.go
src/encoding/json/tags.go
src/encoding/xml/typeinfo.go
src/encoding/xml/xml.go
src/go/build/build.go
src/go/printer/printer.go
src/html/template/js.go
src/math/big/ratconv.go
src/mime/encodedword.go
src/mime/mediatype.go
src/net/http/cgi/child.go
src/net/http/cookie.go
src/net/http/fs.go
src/net/http/request.go
src/net/http/server.go
src/net/lookup_test.go
src/net/url/url.go
src/os/env_test.go
src/os/exec/exec.go
src/os/os_test.go
src/os/user/cgo_lookup_unix.go
src/os/user/lookup_unix.go
src/regexp/exec_test.go
src/regexp/regexp.go
src/runtime/pprof/pprof_test.go
src/unicode/maketables.go

index 8cc78c01ed46ac18edaddecdfc09e66faa47a762..a47909b270486679fc8cdc206af92f804fabff57 100644 (file)
@@ -189,7 +189,7 @@ func main() {
                        features = append(features, f)
                        continue
                }
-               comma := strings.Index(f, ",")
+               comma := strings.IndexByte(f, ',')
                for cname := range cmap {
                        f2 := fmt.Sprintf("%s (%s)%s", f[:comma], cname, f[comma:])
                        features = append(features, f2)
index af0ed216a51865839005780346e709722e7f9684..867db4f11488908add22c3f250682d6a1b050a0f 100644 (file)
@@ -204,7 +204,7 @@ func (p *Package) loadDefines(f *File) {
                line = strings.TrimSpace(line[8:])
 
                var key, val string
-               spaceIndex := strings.Index(line, " ")
+               spaceIndex := strings.IndexByte(line, ' ')
                tabIndex := strings.Index(line, "\t")
 
                if spaceIndex == -1 && tabIndex == -1 {
@@ -364,11 +364,11 @@ func (p *Package) guessKinds(f *File) []*Name {
                        continue
                }
 
-               c1 := strings.Index(line, ":")
+               c1 := strings.IndexByte(line, ':')
                if c1 < 0 {
                        continue
                }
-               c2 := strings.Index(line[c1+1:], ":")
+               c2 := strings.IndexByte(line[c1+1:], ':')
                if c2 < 0 {
                        continue
                }
@@ -2538,7 +2538,7 @@ func fieldPrefix(fld []*ast.Field) string {
                        if strings.HasPrefix(n.Name, "orig_") || strings.HasPrefix(n.Name, "_") {
                                continue
                        }
-                       i := strings.Index(n.Name, "_")
+                       i := strings.IndexByte(n.Name, '_')
                        if i < 0 {
                                continue
                        }
index 6d638f064422a726a84f3232aa53bc388eee9afe..55736363fbdad2bb0a4eadfeec9cf8b575f5c1c8 100644 (file)
@@ -41,7 +41,7 @@ func (p *Package) godefs(f *File, srcfile string) string {
                                continue
                        }
                        s := strings.TrimSpace(c.Text[i+len("+godefs map"):])
-                       i = strings.Index(s, " ")
+                       i = strings.IndexByte(s, ' ')
                        if i < 0 {
                                fmt.Fprintf(os.Stderr, "invalid +godefs map comment: %s\n", c.Text)
                                continue
index 91cf0c80a335222246112713dda14506dde715c9..8acb704635458c56969b3e020525559731da9181 100644 (file)
@@ -540,7 +540,7 @@ func init() {
        for key, val := range knownFormats {
                // key must be "typename format", and format starts with a '%'
                // (formats containing '*' alone are not collected in this table)
-               i := strings.Index(key, "%")
+               i := strings.IndexByte(key, '%')
                if i < 0 || !oneFormat(key[i:]) {
                        log.Fatalf("incorrect knownFormats key: %q", key)
                }
index 6b23d7b076b4900ed3fb91466074b67ae1251b83..5760fa7796106092113aa1e0269834fcfc1fcc0b 100644 (file)
@@ -364,7 +364,7 @@ func Main(archInit func(*Arch)) {
                                // _ in phase name also matches space
                                phase := name[4:]
                                flag := "debug" // default flag is debug
-                               if i := strings.Index(phase, "/"); i >= 0 {
+                               if i := strings.IndexByte(phase, '/'); i >= 0 {
                                        flag = phase[i+1:]
                                        phase = phase[:i]
                                }
@@ -689,7 +689,7 @@ func addImportMap(s string) {
        if strings.Count(s, "=") != 1 {
                log.Fatal("-importmap argument must be of the form source=actual")
        }
-       i := strings.Index(s, "=")
+       i := strings.IndexByte(s, '=')
        source, actual := s[:i], s[i+1:]
        if source == "" || actual == "" {
                log.Fatal("-importmap argument must be of the form source=actual; source and actual must be non-empty")
@@ -712,13 +712,13 @@ func readImportCfg(file string) {
                }
 
                var verb, args string
-               if i := strings.Index(line, " "); i < 0 {
+               if i := strings.IndexByte(line, ' '); i < 0 {
                        verb = line
                } else {
                        verb, args = line[:i], strings.TrimSpace(line[i+1:])
                }
                var before, after string
-               if i := strings.Index(args, "="); i >= 0 {
+               if i := strings.IndexByte(args, '='); i >= 0 {
                        before, after = args[:i], args[i+1:]
                }
                switch verb {
index 851f8723a3708b26460c0bc76fae885b7a2a0bb6..17b826bf3846c2c896e065cbe6c90f21f522fdf3 100644 (file)
@@ -1224,7 +1224,7 @@ func (p *noder) pragma(pos src.Pos, text string) syntax.Pragma {
                fallthrough // because of //go:cgo_unsafe_args
        default:
                verb := text
-               if i := strings.Index(text, " "); i >= 0 {
+               if i := strings.IndexByte(text, ' '); i >= 0 {
                        verb = verb[:i]
                }
                prag := pragmaValue(verb)
index 9d2dcf658f9a7d573f19ba56e8544d3c70fc573c..7f779c2df1d2ff39c365dff5b93bd32559ac32a0 100644 (file)
@@ -1045,7 +1045,7 @@ func (lv *Liveness) showlive(v *ssa.Value, live bvec) {
                s += fmt.Sprintf("entry to %s:", lv.fn.funcname())
        } else if sym, ok := v.Aux.(*obj.LSym); ok {
                fn := sym.Name
-               if pos := strings.Index(fn, "."); pos >= 0 {
+               if pos := strings.IndexByte(fn, '.'); pos >= 0 {
                        fn = fn[pos+1:]
                }
                s += fmt.Sprintf("call to %s:", fn)
index c23a54d9b5dd2b3fe5aee4eab4c6840139cf9628..d35c80cd8a09db5a25f4195ed0b91abbc4c2ca08 100644 (file)
@@ -475,8 +475,8 @@ func genMatch0(w io.Writer, arch arch, match, v string, m map[string]struct{}, t
                }
                // compound sexpr
                var argname string
-               colon := strings.Index(arg, ":")
-               openparen := strings.Index(arg, "(")
+               colon := strings.IndexByte(arg, ':')
+               openparen := strings.IndexByte(arg, '(')
                if colon >= 0 && openparen >= 0 && colon < openparen {
                        // rule-specified name
                        argname = arg[:colon]
@@ -817,7 +817,7 @@ func commute1(m string, cnt map[string]int, arch arch) []string {
        }
        // Split up input.
        var prefix string
-       colon := strings.Index(m, ":")
+       colon := strings.IndexByte(m, ':')
        if colon >= 0 && isVariable(m[:colon]) {
                prefix = m[:colon+1]
                m = m[colon+1:]
@@ -912,7 +912,7 @@ func varCount1(m string, cnt map[string]int) {
                return
        }
        // Split up input.
-       colon := strings.Index(m, ":")
+       colon := strings.IndexByte(m, ':')
        if colon >= 0 && isVariable(m[:colon]) {
                cnt[m[:colon]]++
                m = m[colon+1:]
index 1bba9eeacff314453283b7a4bddd9a031dc2d2ff..9d7beb997f51906b4f9b4ab4f8257a89115ab289 100644 (file)
@@ -313,7 +313,7 @@ func testPos(t *testing.T, list []test, prefix, suffix string, extract func(*Fil
 }
 
 func stripAt(s string) (string, int) {
-       if i := strings.Index(s, "@"); i >= 0 {
+       if i := strings.IndexByte(s, '@'); i >= 0 {
                return s[:i] + s[i+1:], i
        }
        return s, -1
index a72a2607f9f5914d4efb35da0f5ff754d51ba04b..6e63eddfe52515e704a3e2588fe10ef40ffaa85d 100644 (file)
@@ -137,7 +137,7 @@ func main() {
        // so OS X 10.6 is uname version 10 and OS X 10.8 is uname version 12.
        if gohostos == "darwin" {
                rel := run("", CheckExit, "uname", "-r")
-               if i := strings.Index(rel, "."); i >= 0 {
+               if i := strings.IndexByte(rel, '.'); i >= 0 {
                        rel = rel[:i]
                }
                osx, _ := strconv.Atoi(rel)
index de275403a2189b8c05638637c8b3c29d34818695..09f551a45d5b54f51a9f59d94ca25c7c349ca568 100644 (file)
@@ -215,7 +215,7 @@ func parseArgs(args []string) (pkg *build.Package, path, symbol string, more boo
        // slash+1: if there's no slash, the value is -1 and start is 0; otherwise
        // start is the byte after the slash.
        for start := slash + 1; start < len(arg); start = period + 1 {
-               period = strings.Index(arg[start:], ".")
+               period = strings.IndexByte(arg[start:], '.')
                symbol := ""
                if period < 0 {
                        period = len(arg)
index 03c828a5816499590a295bd3ef98cb7b72555708..cdc3c839d32f7903c666b3b47e25cff17796eccb 100644 (file)
@@ -791,7 +791,7 @@ func renameFix(tab []rename) func(*ast.File) bool {
 }
 
 func parseName(s string) (ptr bool, pkg, nam string) {
-       i := strings.Index(s, ".")
+       i := strings.IndexByte(s, '.')
        if i < 0 {
                panic("parseName: invalid name " + s)
        }
index 0352c49db0fe8010b19d5711cf2c244f60a33eba..e2b89edc7da5c1e8ea3ee9cc3065d7d6d5656144 100644 (file)
@@ -471,7 +471,7 @@ func typecheck1(cfg *TypeConfig, f interface{}, typeof map[interface{}]string, a
                        if strings.HasPrefix(t, "[") || strings.HasPrefix(t, "map[") {
                                // Lazy: assume there are no nested [] in the array
                                // length or map key type.
-                               if i := strings.Index(t, "]"); i >= 0 {
+                               if i := strings.IndexByte(t, ']'); i >= 0 {
                                        typeof[n] = t[i+1:]
                                }
                        }
@@ -512,11 +512,11 @@ func typecheck1(cfg *TypeConfig, f interface{}, typeof map[interface{}]string, a
                                key, value = "int", "rune"
                        } else if strings.HasPrefix(t, "[") {
                                key = "int"
-                               if i := strings.Index(t, "]"); i >= 0 {
+                               if i := strings.IndexByte(t, ']'); i >= 0 {
                                        value = t[i+1:]
                                }
                        } else if strings.HasPrefix(t, "map[") {
-                               if i := strings.Index(t, "]"); i >= 0 {
+                               if i := strings.IndexByte(t, ']'); i >= 0 {
                                        key, value = t[4:i], t[i+1:]
                                }
                        }
index 08b3cd0e6a399bdd7eb1bb27a18fe101d9d1b907..a41d91fce524c1f73107fe2976a96a5739fc7822 100644 (file)
@@ -223,7 +223,7 @@ func (tg *testgoData) parallel() {
        }
        for _, e := range tg.env {
                if strings.HasPrefix(e, "GOROOT=") || strings.HasPrefix(e, "GOPATH=") || strings.HasPrefix(e, "GOBIN=") {
-                       val := e[strings.Index(e, "=")+1:]
+                       val := e[strings.IndexByte(e, '=')+1:]
                        if strings.HasPrefix(val, "testdata") || strings.HasPrefix(val, "./testdata") {
                                tg.t.Fatalf("internal testsuite error: call to parallel with testdata in environment (%s)", e)
                        }
index aff33f70d8deb3394e708bf2c20e0edeb840087e..1026ed0fa53823dac0c87df2d22a4afefdf6b4f1 100644 (file)
@@ -54,7 +54,7 @@ var Commands []*Command
 // Name returns the command's name: the first word in the usage line.
 func (c *Command) Name() string {
        name := c.UsageLine
-       i := strings.Index(name, " ")
+       i := strings.IndexByte(name, ' ')
        if i >= 0 {
                name = name[:i]
        }
index 7ab30221279f2a44474c5884d12ec1b1acb20f2e..b14bda89638bf5d353e6bd8188a6dae4c29045dd 100644 (file)
@@ -87,7 +87,7 @@ func Parse(cmd string, defns []*Defn, args []string, i int) (f *Defn, value stri
        name := arg[1:]
        // If there's already a prefix such as "test.", drop it for now.
        name = strings.TrimPrefix(name, cmd+".")
-       equals := strings.Index(name, "=")
+       equals := strings.IndexByte(name, '=')
        if equals >= 0 {
                value = name[equals+1:]
                name = name[:equals]
index 768469c24d591f5140c49b03b2e2bfdc2c70ad01..7acba46db36d2898154c9e522b8c36f861de05d6 100644 (file)
@@ -496,7 +496,7 @@ func downloadPackage(p *load.Package) error {
                return err
        }
        vers := runtime.Version()
-       if i := strings.Index(vers, " "); i >= 0 {
+       if i := strings.IndexByte(vers, ' '); i >= 0 {
                vers = vers[:i]
        }
        if err := vcs.tagSync(root, selectTag(vers, tags)); err != nil {
index 3960cdd1e4ba7b5be61ff77bfb5ca6f4dfad2172..91aad9a3a77d75bd007fadac32268b13f7c3930f 100644 (file)
@@ -699,7 +699,7 @@ func repoRootFromVCSPaths(importPath, scheme string, security web.SecurityMode,
 //
 // This handles custom import paths like "name.tld/pkg/foo" or just "name.tld".
 func repoRootForImportDynamic(importPath string, security web.SecurityMode) (*repoRoot, error) {
-       slash := strings.Index(importPath, "/")
+       slash := strings.IndexByte(importPath, '/')
        if slash < 0 {
                slash = len(importPath)
        }
index b8d67dac742e5a53a3db1eebaab0ef532a527d06..ffc2b0234cc4450a130482949ea7804a5ca85bcc 100644 (file)
@@ -139,7 +139,7 @@ func testStringPairs(t *testing.T, name string, tests []stringPairTest, f func(s
 func testPatterns(t *testing.T, name, tests string, fn func(string, string) bool) {
        var patterns []string
        for _, line := range strings.Split(tests, "\n") {
-               if i := strings.Index(line, "#"); i >= 0 {
+               if i := strings.IndexByte(line, '#'); i >= 0 {
                        line = line[:i]
                }
                f := strings.Fields(line)
index 2f5a7a801824e34eb62722832285eb574e9dae91..6a84caa5c5ccaebbc65dfa72e8f85d0a4da21d62 100644 (file)
@@ -231,7 +231,7 @@ func (p *Package) copyBuild(pp *build.Package) {
 // their own code to $GOROOT instead of using $GOPATH, but we assume that
 // code will start with a domain name (dot in the first element).
 func isStandardImportPath(path string) bool {
-       i := strings.Index(path, "/")
+       i := strings.IndexByte(path, '/')
        if i < 0 {
                i = len(path)
        }
index 45b8c0cd7de909e9210af5d1093fdf4a75b231a2..5dfd10fa92adc6936f4e60d46b4ccc47779f3dd9 100644 (file)
@@ -1074,7 +1074,7 @@ func strnputPad(s string, n int, pad []byte) {
 var strdata []*Symbol
 
 func addstrdata1(ctxt *Link, arg string) {
-       eq := strings.Index(arg, "=")
+       eq := strings.IndexByte(arg, '=')
        dot := strings.LastIndex(arg[:eq+1], ".")
        if eq < 0 || dot < 0 {
                Exitf("-X flag requires argument of the form importpath.name=value")
index 119e406080b291da41fe96895a19ec9e5b6500c0..f9ca346081d90d123ef43853dacb9668d192b60a 100644 (file)
@@ -326,7 +326,7 @@ func (d *deadcodepass) flood() {
                        }
                        for i, m := range methodsigs {
                                name := string(m)
-                               name = name[:strings.Index(name, "(")]
+                               name = name[:strings.IndexByte(name, '(')]
                                if !strings.HasSuffix(methods[i].ifn().Name, name) {
                                        panic(fmt.Sprintf("%q relocation for %q does not match method %q", s.Name, methods[i].ifn().Name, name))
                                }
index cf49c3faba217c088b8c8a30e50ea55b6e3f2776..1494ca87eb5840a2d5172644886056ce0f64fb95 100644 (file)
@@ -184,7 +184,7 @@ func loadcgo(ctxt *Link, file string, pkg string, p string) {
 
                        local = expandpkg(local, pkg)
                        q = ""
-                       if i := strings.Index(remote, "#"); i >= 0 {
+                       if i := strings.IndexByte(remote, '#'); i >= 0 {
                                remote, q = remote[:i], remote[i+1:]
                        }
                        s = ctxt.Syms.Lookup(local, 0)
index 9bbc94faa61d9f555f3ec6b226f3965823bc0a75..9789256251624a5f771e5066175cc901a22cfc0b 100644 (file)
@@ -60,13 +60,13 @@ func (ctxt *Link) readImportCfg(file string) {
                }
 
                var verb, args string
-               if i := strings.Index(line, " "); i < 0 {
+               if i := strings.IndexByte(line, ' '); i < 0 {
                        verb = line
                } else {
                        verb, args = line[:i], strings.TrimSpace(line[i+1:])
                }
                var before, after string
-               if i := strings.Index(args, "="); i >= 0 {
+               if i := strings.IndexByte(args, '='); i >= 0 {
                        before, after = args[:i], args[i+1:]
                }
                switch verb {
index b01d23d342ba5372f2c06ffbf829ab2e5d8bc1dc..1a9310204b308901f08e341f13f17500e59fea95 100644 (file)
@@ -678,7 +678,7 @@ func asmCheckVar(badf func(string, ...interface{}), fn *asmFunc, line, expr stri
 
        // Determine whether the match we're holding
        // is the first or second argument.
-       if strings.Index(line, expr) > strings.Index(line, ",") {
+       if strings.Index(line, expr) > strings.IndexByte(line, ',') {
                kind = dst
        } else {
                kind = src
index 21bb0d09972a698f743b020ae4690f8d8001bea7..67a96ed2c4febccb41c7393490a599d97fde7058 100644 (file)
@@ -303,7 +303,7 @@ func (s *formatState) parseIndex() bool {
        start := s.nbytes
        s.scanNum()
        if s.nbytes == len(s.format) || s.nbytes == start || s.format[s.nbytes] != ']' {
-               end := strings.Index(s.format, "]")
+               end := strings.IndexByte(s.format, ']')
                if end < 0 {
                        end = len(s.format)
                }
index cfa816694e039842f62bddda98fe94f7ea1edba1..c3ec43105978f8fb2a7ded80e14c2eceaa08ad48 100644 (file)
@@ -63,7 +63,7 @@ func checkCanonicalFieldTag(f *File, field *ast.Field, seen *map[[2]string]token
                        // by containing a field named XMLName; see issue 18256.
                        continue
                }
-               if i := strings.Index(val, ","); i >= 0 {
+               if i := strings.IndexByte(val, ','); i >= 0 {
                        if key == "xml" {
                                // Use a separate namespace for XML attributes.
                                for _, opt := range strings.Split(val[i:], ",") {
index 0388d63e1495396ca41c1985ce350b74e08bb622..21eb4325b8db5133fa8b0eee9b5e7fd7573a142e 100644 (file)
@@ -118,7 +118,7 @@ func DecryptPEMBlock(b *pem.Block, password []byte) ([]byte, error) {
                return nil, errors.New("x509: no DEK-Info header in block")
        }
 
-       idx := strings.Index(dek, ",")
+       idx := strings.IndexByte(dek, ',')
        if idx == -1 {
                return nil, errors.New("x509: malformed DEK-Info header")
        }
index fc2488adc6fa56f25384c9da7021a0728af04679..53aef93c21f99402db19be19a58834498e7b311c 100644 (file)
@@ -161,7 +161,7 @@ func fetchCertIDs() ([]certID, error) {
                }
                if strings.HasPrefix(ln, sn) {
                        // extract hex value from parentheses.
-                       id.serialNumber = ln[strings.Index(ln, "(")+1 : len(ln)-1]
+                       id.serialNumber = ln[strings.IndexByte(ln, '(')+1 : len(ln)-1]
                        continue
                }
                if strings.TrimSpace(ln) == "X509v3 Subject Key Identifier:" {
index f5f996309509167bb8c40380c1510058eddc88c3..b81f872801e18d0401c29c2832916bebe9bcd421 100644 (file)
@@ -45,7 +45,7 @@ func (s *Sym) PackageName() string {
                pathend = 0
        }
 
-       if i := strings.Index(s.Name[pathend:], "."); i != -1 {
+       if i := strings.IndexByte(s.Name[pathend:], '.'); i != -1 {
                return s.Name[:pathend+i]
        }
        return ""
@@ -58,7 +58,7 @@ func (s *Sym) ReceiverName() string {
        if pathend < 0 {
                pathend = 0
        }
-       l := strings.Index(s.Name[pathend:], ".")
+       l := strings.IndexByte(s.Name[pathend:], '.')
        r := strings.LastIndex(s.Name[pathend:], ".")
        if l == -1 || r == -1 || l == r {
                return ""
index c38fd5102f6302deb1e10639dbe4552ee255837e..6a8d03a5df24fbe6f4bddf5b5f3c1e9d3d84dbaf 100644 (file)
@@ -15,7 +15,7 @@ type tagOptions string
 // parseTag splits a struct field's json tag into its name and
 // comma-separated options.
 func parseTag(tag string) (string, tagOptions) {
-       if idx := strings.Index(tag, ","); idx != -1 {
+       if idx := strings.IndexByte(tag, ','); idx != -1 {
                return tag[:idx], tagOptions(tag[idx+1:])
        }
        return tag, tagOptions("")
@@ -31,7 +31,7 @@ func (o tagOptions) Contains(optionName string) bool {
        s := string(o)
        for s != "" {
                var next string
-               i := strings.Index(s, ",")
+               i := strings.IndexByte(s, ',')
                if i >= 0 {
                        s, next = s[:i], s[i+1:]
                }
index 2e7ae935a8bb9803cab1171722a4f6d2dada53c6..b3346d304ef820514b00713f11e6d2fc1005ce75 100644 (file)
@@ -115,7 +115,7 @@ func structFieldInfo(typ reflect.Type, f *reflect.StructField) (*fieldInfo, erro
 
        // Split the tag from the xml namespace if necessary.
        tag := f.Tag.Get("xml")
-       if i := strings.Index(tag, " "); i >= 0 {
+       if i := strings.IndexByte(tag, ' '); i >= 0 {
                finfo.xmlns, tag = tag[:i], tag[i+1:]
        }
 
index be90b62c9a0fc7ff33b77ff72d2d1822093437b8..27b871649be09a548cfa65fc2dbfb29886bb6ef9 100644 (file)
@@ -1161,7 +1161,7 @@ func (d *Decoder) nsname() (name Name, ok bool) {
        if !ok {
                return
        }
-       i := strings.Index(s, ":")
+       i := strings.IndexByte(s, ':')
        if i < 0 {
                name.Local = s
        } else {
index d8163d01723cfa77005b6f356cb7f4051071b726..9822affa8a6fdb7735ec938ce6830948a4810899 100644 (file)
@@ -1247,7 +1247,7 @@ func (ctxt *Context) saveCgo(filename string, di *Package, cg *ast.CommentGroup)
 
                // Split at colon.
                line = strings.TrimSpace(line[4:])
-               i := strings.Index(line, ":")
+               i := strings.IndexByte(line, ':')
                if i < 0 {
                        return fmt.Errorf("%s: invalid #cgo line: %s", filename, orig)
                }
@@ -1462,7 +1462,7 @@ func (ctxt *Context) match(name string, allTags map[string]bool) bool {
                }
                return false
        }
-       if i := strings.Index(name, ","); i >= 0 {
+       if i := strings.IndexByte(name, ','); i >= 0 {
                // comma-separated list
                ok1 := ctxt.match(name[:i], allTags)
                ok2 := ctxt.match(name[i+1:], allTags)
@@ -1526,7 +1526,7 @@ func (ctxt *Context) match(name string, allTags map[string]bool) bool {
 //
 // An exception: if GOOS=android, then files with GOOS=linux are also matched.
 func (ctxt *Context) goodOSArchFile(name string, allTags map[string]bool) bool {
-       if dot := strings.Index(name, "."); dot != -1 {
+       if dot := strings.IndexByte(name, '.'); dot != -1 {
                name = name[:dot]
        }
 
@@ -1537,7 +1537,7 @@ func (ctxt *Context) goodOSArchFile(name string, allTags map[string]bool) bool {
        // systems, such as android, to arrive without breaking existing code with
        // innocuous source code in "android.go". The easiest fix: cut everything
        // in the name before the initial _.
-       i := strings.Index(name, "_")
+       i := strings.IndexByte(name, '_')
        if i < 0 {
                return true
        }
index dbb4bbd90cf205cfbc9304b23ca63ccb81803f71..4f4beadcab23e5456ccda9df28e99a3b51ede3ce 100644 (file)
@@ -537,7 +537,7 @@ func stripCommonPrefix(lines []string) {
         * Check for vertical "line of stars" and correct prefix accordingly.
         */
        lineOfStars := false
-       if i := strings.Index(prefix, "*"); i >= 0 {
+       if i := strings.IndexByte(prefix, '*'); i >= 0 {
                // Line of stars present.
                if i > 0 && prefix[i-1] == ' ' {
                        i-- // remove trailing blank from prefix so stars remain aligned
index 239395f8d3a53bb26d911b3089a3df23ee716722..d80ead5ed2572935b77da5416a371c973932ed0d 100644 (file)
@@ -374,7 +374,7 @@ func isJSType(mimeType string) bool {
        //   https://www.ietf.org/rfc/rfc4627.txt
        mimeType = strings.ToLower(mimeType)
        // discard parameters
-       if i := strings.Index(mimeType, ";"); i >= 0 {
+       if i := strings.IndexByte(mimeType, ';'); i >= 0 {
                mimeType = mimeType[:i]
        }
        mimeType = strings.TrimSpace(mimeType)
index 4bc6ef7e8063edb648e20cf2187e17d3b40dd51c..3b43b19f0e3b0f656f1b72d044fb38b466662de0 100644 (file)
@@ -49,7 +49,7 @@ func (z *Rat) SetString(s string) (*Rat, bool) {
        // len(s) > 0
 
        // parse fraction a/b, if any
-       if sep := strings.Index(s, "/"); sep >= 0 {
+       if sep := strings.IndexByte(s, '/'); sep >= 0 {
                if _, ok := z.a.SetString(s[:sep], 0); !ok {
                        return nil, false
                }
index 99eb432f54e172dcf65c9a5a54ba45a869f26c5b..bb49d65873a79303107a8179c5198875f225d226 100644 (file)
@@ -257,7 +257,7 @@ func (d *WordDecoder) DecodeHeader(header string) (string, error) {
                }
                cur := start + len("=?")
 
-               i := strings.Index(header[cur:], "?")
+               i := strings.IndexByte(header[cur:], '?')
                if i == -1 {
                        break
                }
index b8a83d6f79c1a7750768b6c6d49a2b1678bc30db..7ec67cd584e4911057db37234ce2c0a199f1eb46 100644 (file)
@@ -20,7 +20,7 @@ import (
 // FormatMediaType returns the empty string.
 func FormatMediaType(t string, param map[string]string) string {
        var b bytes.Buffer
-       if slash := strings.Index(t, "/"); slash == -1 {
+       if slash := strings.IndexByte(t, '/'); slash == -1 {
                if !isToken(t) {
                        return ""
                }
@@ -110,7 +110,7 @@ var ErrInvalidMediaParameter = errors.New("mime: invalid media parameter")
 // The returned map, params, maps from the lowercase
 // attribute to the attribute value with its case preserved.
 func ParseMediaType(v string) (mediatype string, params map[string]string, err error) {
-       i := strings.Index(v, ";")
+       i := strings.IndexByte(v, ';')
        if i == -1 {
                i = len(v)
        }
@@ -146,7 +146,7 @@ func ParseMediaType(v string) (mediatype string, params map[string]string, err e
                }
 
                pmap := params
-               if idx := strings.Index(key, "*"); idx != -1 {
+               if idx := strings.IndexByte(key, '*'); idx != -1 {
                        baseName := key[:idx]
                        if continuation == nil {
                                continuation = make(map[string]map[string]string)
index ec1010882196c888c28c7ca557a954a95003e51e..2c762bdba9e832e9b9215e55d2defd04ca80d582 100644 (file)
@@ -40,7 +40,7 @@ func Request() (*http.Request, error) {
 func envMap(env []string) map[string]string {
        m := make(map[string]string)
        for _, kv := range env {
-               if idx := strings.Index(kv, "="); idx != -1 {
+               if idx := strings.IndexByte(kv, '='); idx != -1 {
                        m[kv[:idx]] = kv[idx+1:]
                }
        }
index 38b1b3630e291de3fb2749795eb72ff2765e94a7..6642a2469543f5708e853ea9edcf5d8ae9fe339d 100644 (file)
@@ -50,7 +50,7 @@ func readSetCookies(h Header) []*Cookie {
                        continue
                }
                parts[0] = strings.TrimSpace(parts[0])
-               j := strings.Index(parts[0], "=")
+               j := strings.IndexByte(parts[0], '=')
                if j < 0 {
                        continue
                }
@@ -74,7 +74,7 @@ func readSetCookies(h Header) []*Cookie {
                        }
 
                        attr, val := parts[i], ""
-                       if j := strings.Index(attr, "="); j >= 0 {
+                       if j := strings.IndexByte(attr, '='); j >= 0 {
                                attr, val = attr[:j], attr[j+1:]
                        }
                        lowerAttr := strings.ToLower(attr)
@@ -214,7 +214,7 @@ func readCookies(h Header, filter string) []*Cookie {
                                continue
                        }
                        name, val := parts[i], ""
-                       if j := strings.Index(name, "="); j >= 0 {
+                       if j := strings.IndexByte(name, '='); j >= 0 {
                                name, val = name[:j], name[j+1:]
                        }
                        if !isCookieNameValid(name) {
index ecad14ac1e4a62c08e1a0b244a4f6581c7ea6e61..e17a6d8f3f89a6fa74da3fb3679919a727d06717 100644 (file)
@@ -748,7 +748,7 @@ func parseRange(s string, size int64) ([]httpRange, error) {
                if ra == "" {
                        continue
                }
-               i := strings.Index(ra, "-")
+               i := strings.IndexByte(ra, '-')
                if i < 0 {
                        return nil, errors.New("invalid range")
                }
index 870af85e04a002b1fd078e71441a4d1671641c2e..b7fcf806ba117992d677452388ae9d5d6997da23 100644 (file)
@@ -712,7 +712,7 @@ func ParseHTTPVersion(vers string) (major, minor int, ok bool) {
        if !strings.HasPrefix(vers, "HTTP/") {
                return 0, 0, false
        }
-       dot := strings.Index(vers, ".")
+       dot := strings.IndexByte(vers, '.')
        if dot < 0 {
                return 0, 0, false
        }
@@ -880,8 +880,8 @@ func (r *Request) SetBasicAuth(username, password string) {
 
 // parseRequestLine parses "GET /foo HTTP/1.1" into its three parts.
 func parseRequestLine(line string) (method, requestURI, proto string, ok bool) {
-       s1 := strings.Index(line, " ")
-       s2 := strings.Index(line[s1+1:], " ")
+       s1 := strings.IndexByte(line, ' ')
+       s2 := strings.IndexByte(line[s1+1:], ' ')
        if s1 < 0 || s2 < 0 {
                return
        }
index ffbba81c6059be9e598b2742ff6c8fc49acff5c3..d89f66058ac7b44d584c68552f51a6770b808d70 100644 (file)
@@ -2002,7 +2002,7 @@ func Redirect(w ResponseWriter, r *Request, url string, code int) {
                        }
 
                        var query string
-                       if i := strings.Index(url, "?"); i != -1 {
+                       if i := strings.IndexByte(url, '?'); i != -1 {
                                url, query = url[:i], url[i:]
                        }
 
index 68a7abe95dfbf13124b25be9add619ab815fba02..fc184154da3629586dc75d84bd56488f892937c9 100644 (file)
@@ -475,7 +475,7 @@ func TestLookupDotsWithLocalSource(t *testing.T) {
                }
        loop:
                for i, name := range names {
-                       if strings.Index(name, ".") == len(name)-1 { // "localhost" not "localhost."
+                       if strings.IndexByte(name, '.') == len(name)-1 { // "localhost" not "localhost."
                                for j := range names {
                                        if j == i {
                                                continue
index c9353ab080d72abaf669ab8874037982a737e8ce..02d446e4a2dbacf441c16a3e6e48caeecf3a4b7d 100644 (file)
@@ -505,8 +505,8 @@ func parse(rawurl string, viaRequest bool) (*URL, error) {
                // RFC 3986, ยง3.3:
                // In addition, a URI reference (Section 4.1) may be a relative-path reference,
                // in which case the first path segment cannot contain a colon (":") character.
-               colon := strings.Index(rest, ":")
-               slash := strings.Index(rest, "/")
+               colon := strings.IndexByte(rest, ':')
+               slash := strings.IndexByte(rest, '/')
                if colon >= 0 && (slash < 0 || colon < slash) {
                        // First path segment has colon. Not allowed in relative URL.
                        return nil, errors.New("first path segment in URL cannot contain colon")
@@ -830,7 +830,7 @@ func parseQuery(m Values, query string) (err error) {
                        continue
                }
                value := ""
-               if i := strings.Index(key, "="); i >= 0 {
+               if i := strings.IndexByte(key, '='); i >= 0 {
                        key, value = key[:i], key[i+1:]
                }
                key, err1 := QueryUnescape(key)
index e5749f0e8996113951316d84c53e713dbae0923a..d51097e20d1c4027e7c1e7ad14492be7a8293e4a 100644 (file)
@@ -104,7 +104,7 @@ func TestClearenv(t *testing.T) {
                for _, pair := range origEnv {
                        // Environment variables on Windows can begin with =
                        // http://blogs.msdn.com/b/oldnewthing/archive/2010/05/06/10008132.aspx
-                       i := strings.Index(pair[1:], "=") + 1
+                       i := strings.IndexByte(pair[1:], '=') + 1
                        if err := Setenv(pair[:i], pair[i+1:]); err != nil {
                                t.Errorf("Setenv(%q, %q) failed during reset: %v", pair[:i], pair[i+1:], err)
                        }
index b0fe14d6fdd77170a29ddc238eec7214e654904c..bd07a6a73d21ede73a0d2ab8cb31b01fc74f77d4 100644 (file)
@@ -687,7 +687,7 @@ func dedupEnvCase(caseInsensitive bool, env []string) []string {
        out := make([]string, 0, len(env))
        saw := map[string]int{} // key => index into out
        for _, kv := range env {
-               eq := strings.Index(kv, "=")
+               eq := strings.IndexByte(kv, '=')
                if eq < 0 {
                        out = append(out, kv)
                        continue
index 86f8652a2e6fb3c984ad57247bad7c27805c227b..5397dbe148e8f7667da002554fa8f3ebb1c32d05 100644 (file)
@@ -1523,7 +1523,7 @@ func TestHostname(t *testing.T) {
        }
        want := runBinHostname(t)
        if hostname != want {
-               i := strings.Index(hostname, ".")
+               i := strings.IndexByte(hostname, '.')
                if i < 0 || hostname[0:i] != want {
                        t.Errorf("Hostname() = %q, want %q", hostname, want)
                }
index 6f66851bbbc9c8c0818f51e71a68b65f6e172d89..7d92cb213819e48371c55f63620fe9a890bbbd2c 100644 (file)
@@ -124,7 +124,7 @@ func buildUser(pwd *C.struct_passwd) *User {
        // say: "It is expected to be a comma separated list of
        // personal data where the first item is the full name of the
        // user."
-       if i := strings.Index(u.Name, ","); i >= 0 {
+       if i := strings.IndexByte(u.Name, ','); i >= 0 {
                u.Name = u.Name[:i]
        }
        return u
index 5f34ba8611c9b8121b8a6a6982182301c8b9e081..f4c2f670d2041876df3836ed00cbb2eca5abd285 100644 (file)
@@ -131,7 +131,7 @@ func matchUserIndexValue(value string, idx int) lineFunc {
                // say: "It is expected to be a comma separated list of
                // personal data where the first item is the full name of the
                // user."
-               if i := strings.Index(u.Name, ","); i >= 0 {
+               if i := strings.IndexByte(u.Name, ','); i >= 0 {
                        u.Name = u.Name[:i]
                }
                return u, nil
index 5f8e747b17bc1f447722fee9c609003541d4e489..5b827a528d7399392b8465e308c9652f5ba9605d 100644 (file)
@@ -294,7 +294,7 @@ func parseResult(t *testing.T, file string, lineno int, res string) []int {
                                out[n] = -1
                                out[n+1] = -1
                        } else {
-                               k := strings.Index(pair, "-")
+                               k := strings.IndexByte(pair, '-')
                                if k < 0 {
                                        t.Fatalf("%s:%d: invalid pair %s", file, lineno, pair)
                                }
@@ -457,7 +457,7 @@ Reading:
                                continue Reading
                        }
                case ':':
-                       i := strings.Index(flag[1:], ":")
+                       i := strings.IndexByte(flag[1:], ':')
                        if i < 0 {
                                t.Logf("skip: %s", line)
                                continue Reading
index b1af23e85040e3c2a64361b16958ad9ef1ca8ad7..f8643e5a547adadc7ec36a989704ce3adb5819d4 100644 (file)
@@ -829,7 +829,7 @@ func (re *Regexp) ExpandString(dst []byte, template string, src string, match []
 
 func (re *Regexp) expand(dst []byte, template string, bsrc []byte, src string, match []int) []byte {
        for len(template) > 0 {
-               i := strings.Index(template, "$")
+               i := strings.IndexByte(template, '$')
                if i < 0 {
                        break
                }
index 955964c721ec3c89205442c6afb4bdc9ab61043a..64325eb6bb68d097228cdf2132ebcf9126979e3a 100644 (file)
@@ -213,7 +213,7 @@ func profileOk(t *testing.T, need []string, prof bytes.Buffer, duration time.Dur
                fprintStack(&buf, stk)
                samples += count
                for i, name := range need {
-                       if semi := strings.Index(name, ";"); semi > -1 {
+                       if semi := strings.IndexByte(name, ';'); semi > -1 {
                                kv := strings.SplitN(name[semi+1:], "=", 2)
                                if len(kv) != 2 || !contains(labels[kv[0]], kv[1]) {
                                        continue
index 9a92a0130a0b8a1c7f06bd6757fe4c50bb6ceba1..dcfd471b05cff7d629530bfbf9bb12284e18927e 100644 (file)
@@ -680,7 +680,7 @@ func verifyRange(name string, inCategory Op, table *unicode.RangeTable) {
 }
 
 func parseScript(line string, scripts map[string][]Script) {
-       comment := strings.Index(line, "#")
+       comment := strings.IndexByte(line, '#')
        if comment >= 0 {
                line = line[0:comment]
        }