diff options
author | Marvin Stenger <marvin.stenger94@gmail.com> | 2017-09-21 19:01:27 +0200 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2017-09-25 17:35:41 +0000 |
commit | f22ba1f24786be600bfa3686a7ce5a318a96b9c9 (patch) | |
tree | 06dd4fd49b65d66491a3674f8ed440fd44f52cc5 /src/mime | |
parent | 5e92c411284f1757c3531a70530170f1079ee5fc (diff) | |
download | go-f22ba1f24786be600bfa3686a7ce5a318a96b9c9.tar.gz go-f22ba1f24786be600bfa3686a7ce5a318a96b9c9.zip |
all: prefer strings.IndexByte over strings.Index
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>
Diffstat (limited to 'src/mime')
-rw-r--r-- | src/mime/encodedword.go | 2 | ||||
-rw-r--r-- | src/mime/mediatype.go | 6 |
2 files changed, 4 insertions, 4 deletions
diff --git a/src/mime/encodedword.go b/src/mime/encodedword.go index 99eb432f54..bb49d65873 100644 --- a/src/mime/encodedword.go +++ b/src/mime/encodedword.go @@ -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 } diff --git a/src/mime/mediatype.go b/src/mime/mediatype.go index b8a83d6f79..7ec67cd584 100644 --- a/src/mime/mediatype.go +++ b/src/mime/mediatype.go @@ -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) |