Commit 5e42658f authored by Marvin Stenger's avatar Marvin Stenger Committed by Ian Lance Taylor

all: prefer bytes.IndexByte over bytes.Index

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: default avatarIan Lance Taylor <iant@golang.org>
parent d2826d3e
...@@ -758,7 +758,7 @@ func genhash(ctxt *Link, lib *Library) { ...@@ -758,7 +758,7 @@ func genhash(ctxt *Link, lib *Library) {
Errorf(nil, "%s: error reading package data: %v", lib.File, err) Errorf(nil, "%s: error reading package data: %v", lib.File, err)
return return
} }
firstEOL := bytes.Index(pkgDefBytes, []byte("\n")) firstEOL := bytes.IndexByte(pkgDefBytes, '\n')
if firstEOL < 0 { if firstEOL < 0 {
Errorf(nil, "cannot parse package data of %s for hash generation, no newline found", lib.File) Errorf(nil, "cannot parse package data of %s for hash generation, no newline found", lib.File)
return return
......
...@@ -85,7 +85,7 @@ func (o *opensslOutputSink) Write(data []byte) (n int, err error) { ...@@ -85,7 +85,7 @@ func (o *opensslOutputSink) Write(data []byte) (n int, err error) {
o.all = append(o.all, data...) o.all = append(o.all, data...)
for { for {
i := bytes.Index(o.line, []byte{'\n'}) i := bytes.IndexByte(o.line, '\n')
if i < 0 { if i < 0 {
break break
} }
......
...@@ -88,7 +88,7 @@ func (u unmarshalerText) MarshalText() ([]byte, error) { ...@@ -88,7 +88,7 @@ func (u unmarshalerText) MarshalText() ([]byte, error) {
} }
func (u *unmarshalerText) UnmarshalText(b []byte) error { func (u *unmarshalerText) UnmarshalText(b []byte) error {
pos := bytes.Index(b, []byte(":")) pos := bytes.IndexByte(b, ':')
if pos == -1 { if pos == -1 {
return errors.New("missing separator") return errors.New("missing separator")
} }
......
...@@ -36,7 +36,7 @@ type Block struct { ...@@ -36,7 +36,7 @@ type Block struct {
// bytes) is also returned and this will always be smaller than the original // bytes) is also returned and this will always be smaller than the original
// argument. // argument.
func getLine(data []byte) (line, rest []byte) { func getLine(data []byte) (line, rest []byte) {
i := bytes.Index(data, []byte{'\n'}) i := bytes.IndexByte(data, '\n')
var j int var j int
if i < 0 { if i < 0 {
i = len(data) i = len(data)
...@@ -106,7 +106,7 @@ func Decode(data []byte) (p *Block, rest []byte) { ...@@ -106,7 +106,7 @@ func Decode(data []byte) (p *Block, rest []byte) {
} }
line, next := getLine(rest) line, next := getLine(rest)
i := bytes.Index(line, []byte{':'}) i := bytes.IndexByte(line, ':')
if i == -1 { if i == -1 {
break break
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment