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/regexp | |
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/regexp')
-rw-r--r-- | src/regexp/exec_test.go | 4 | ||||
-rw-r--r-- | src/regexp/regexp.go | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/src/regexp/exec_test.go b/src/regexp/exec_test.go index 5f8e747b17..5b827a528d 100644 --- a/src/regexp/exec_test.go +++ b/src/regexp/exec_test.go @@ -294,7 +294,7 @@ func parseResult(t *testing.T, file string, lineno int, res string) []int { out[n] = -1 out[n+1] = -1 } else { - k := strings.Index(pair, "-") + k := strings.IndexByte(pair, '-') if k < 0 { t.Fatalf("%s:%d: invalid pair %s", file, lineno, pair) } @@ -457,7 +457,7 @@ Reading: continue Reading } case ':': - i := strings.Index(flag[1:], ":") + i := strings.IndexByte(flag[1:], ':') if i < 0 { t.Logf("skip: %s", line) continue Reading diff --git a/src/regexp/regexp.go b/src/regexp/regexp.go index b1af23e850..f8643e5a54 100644 --- a/src/regexp/regexp.go +++ b/src/regexp/regexp.go @@ -829,7 +829,7 @@ func (re *Regexp) ExpandString(dst []byte, template string, src string, match [] func (re *Regexp) expand(dst []byte, template string, bsrc []byte, src string, match []int) []byte { for len(template) > 0 { - i := strings.Index(template, "$") + i := strings.IndexByte(template, '$') if i < 0 { break } |