]> Cypherpunks repositories - gostls13.git/commitdiff
all: prefer bytes.IndexByte over bytes.Index
authorMarvin Stenger <marvin.stenger94@gmail.com>
Thu, 21 Sep 2017 17:23:51 +0000 (19:23 +0200)
committerIan Lance Taylor <iant@golang.org>
Wed, 27 Sep 2017 01:09:13 +0000 (01:09 +0000)
bytes.IndexByte can be used wherever the second argument to
strings.Index is exactly one byte long, so we do that with this change.

This avoids generating unnecessary string symbols/converison and saves
a few calls to bytes.Index.

Change-Id: If31c775790e01edfece1169e398ad6a754fb4428
Reviewed-on: https://go-review.googlesource.com/66373
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/link/internal/ld/lib.go
src/crypto/tls/handshake_client_test.go
src/encoding/json/decode_test.go
src/encoding/pem/pem.go

index a1413820c733440148619b89d81313710dfccf25..709790bc3d55882a03081e494f00a02b17227132 100644 (file)
@@ -758,7 +758,7 @@ func genhash(ctxt *Link, lib *Library) {
                Errorf(nil, "%s: error reading package data: %v", lib.File, err)
                return
        }
-       firstEOL := bytes.Index(pkgDefBytes, []byte("\n"))
+       firstEOL := bytes.IndexByte(pkgDefBytes, '\n')
        if firstEOL < 0 {
                Errorf(nil, "cannot parse package data of %s for hash generation, no newline found", lib.File)
                return
index eaef8aa7a1b6563f72e22d2f5980ab1fc3ff988e..cc3ab714a6322121c778b098a6fd1df407e4b658 100644 (file)
@@ -85,7 +85,7 @@ func (o *opensslOutputSink) Write(data []byte) (n int, err error) {
        o.all = append(o.all, data...)
 
        for {
-               i := bytes.Index(o.line, []byte{'\n'})
+               i := bytes.IndexByte(o.line, '\n')
                if i < 0 {
                        break
                }
index bd38ddd319085cfa2c2c6d8ad053ac3bd1ae18cb..5a72f3a7c6dbc3ec500e059b5258a3b6ae4e11ba 100644 (file)
@@ -88,7 +88,7 @@ func (u unmarshalerText) MarshalText() ([]byte, error) {
 }
 
 func (u *unmarshalerText) UnmarshalText(b []byte) error {
-       pos := bytes.Index(b, []byte(":"))
+       pos := bytes.IndexByte(b, ':')
        if pos == -1 {
                return errors.New("missing separator")
        }
index 5e1ab90cffc08effcdf911bbc086a18984876089..887647b570e4e50d8f470bae5869f91877b16da9 100644 (file)
@@ -36,7 +36,7 @@ type Block struct {
 // bytes) is also returned and this will always be smaller than the original
 // argument.
 func getLine(data []byte) (line, rest []byte) {
-       i := bytes.Index(data, []byte{'\n'})
+       i := bytes.IndexByte(data, '\n')
        var j int
        if i < 0 {
                i = len(data)
@@ -106,7 +106,7 @@ func Decode(data []byte) (p *Block, rest []byte) {
                }
                line, next := getLine(rest)
 
-               i := bytes.Index(line, []byte{':'})
+               i := bytes.IndexByte(line, ':')
                if i == -1 {
                        break
                }