aboutsummaryrefslogtreecommitdiff
path: root/src/encoding
diff options
context:
space:
mode:
authorMarvin Stenger <marvin.stenger94@gmail.com>2017-09-21 19:01:27 +0200
committerIan Lance Taylor <iant@golang.org>2017-09-25 17:35:41 +0000
commitf22ba1f24786be600bfa3686a7ce5a318a96b9c9 (patch)
tree06dd4fd49b65d66491a3674f8ed440fd44f52cc5 /src/encoding
parent5e92c411284f1757c3531a70530170f1079ee5fc (diff)
downloadgo-f22ba1f24786be600bfa3686a7ce5a318a96b9c9.tar.xz
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/encoding')
-rw-r--r--src/encoding/json/tags.go4
-rw-r--r--src/encoding/xml/typeinfo.go2
-rw-r--r--src/encoding/xml/xml.go2
3 files changed, 4 insertions, 4 deletions
diff --git a/src/encoding/json/tags.go b/src/encoding/json/tags.go
index c38fd5102f..6a8d03a5df 100644
--- a/src/encoding/json/tags.go
+++ b/src/encoding/json/tags.go
@@ -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:]
}
diff --git a/src/encoding/xml/typeinfo.go b/src/encoding/xml/typeinfo.go
index 2e7ae935a8..b3346d304e 100644
--- a/src/encoding/xml/typeinfo.go
+++ b/src/encoding/xml/typeinfo.go
@@ -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:]
}
diff --git a/src/encoding/xml/xml.go b/src/encoding/xml/xml.go
index be90b62c9a..27b871649b 100644
--- a/src/encoding/xml/xml.go
+++ b/src/encoding/xml/xml.go
@@ -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 {