diff options
| author | Marvin Stenger <marvin.stenger94@gmail.com> | 2017-09-21 19:23:51 +0200 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2017-09-27 01:09:13 +0000 |
| commit | 5e42658fc04c8f4ce15f3e2d75f4f5d045640738 (patch) | |
| tree | 605b780803869f61926d380b586ca0f010b3f0ee /src/encoding | |
| parent | d2826d3e068f096f4b5371175afb7e5d8c4aa73c (diff) | |
| download | go-5e42658fc04c8f4ce15f3e2d75f4f5d045640738.tar.xz | |
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: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/encoding')
| -rw-r--r-- | src/encoding/json/decode_test.go | 2 | ||||
| -rw-r--r-- | src/encoding/pem/pem.go | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/src/encoding/json/decode_test.go b/src/encoding/json/decode_test.go index bd38ddd319..5a72f3a7c6 100644 --- a/src/encoding/json/decode_test.go +++ b/src/encoding/json/decode_test.go @@ -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") } diff --git a/src/encoding/pem/pem.go b/src/encoding/pem/pem.go index 5e1ab90cff..887647b570 100644 --- a/src/encoding/pem/pem.go +++ b/src/encoding/pem/pem.go @@ -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 } |
