]> Cypherpunks repositories - gostls13.git/commitdiff
bytes, strings: declare variables inside loop they're used in
authorEric Lagergren <ericscottlagergren@gmail.com>
Mon, 3 Apr 2017 23:08:13 +0000 (16:08 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 3 Apr 2017 23:30:36 +0000 (23:30 +0000)
The recently updated Count functions declare variables before
special-cased returns.

Change-Id: I8f726118336b7b0ff72117d12adc48b6e37e60ea
Reviewed-on: https://go-review.googlesource.com/39357
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/bytes/bytes.go
src/strings/strings.go

index de3bd0515a122d2e69019795276abd74a40e1e82..7c878af688cc71462ab4e8bcbfa7cdaf6256f7b2 100644 (file)
@@ -48,11 +48,11 @@ func explode(s []byte, n int) [][]byte {
 
 // countGeneric actually implements Count
 func countGeneric(s, sep []byte) int {
-       n := 0
        // special case
        if len(sep) == 0 {
                return utf8.RuneCount(s) + 1
        }
+       n := 0
        for {
                i := Index(s, sep)
                if i == -1 {
index 9ca222fdfa6dcc7b3075ffcc2d5b9d73a16a58c4..2650fb057ca5977bb38ef8e6e6c85c566fadb522 100644 (file)
@@ -75,11 +75,11 @@ func hashStrRev(sep string) (uint32, uint32) {
 // Count counts the number of non-overlapping instances of substr in s.
 // If substr is an empty string, Count returns 1 + the number of Unicode code points in s.
 func Count(s, substr string) int {
-       n := 0
        // special case
        if len(substr) == 0 {
                return utf8.RuneCountInString(s) + 1
        }
+       n := 0
        for {
                i := Index(s, substr)
                if i == -1 {