From: Eric Lagergren Date: Mon, 3 Apr 2017 23:08:13 +0000 (-0700) Subject: bytes, strings: declare variables inside loop they're used in X-Git-Tag: go1.9beta1~837 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=59f6549d1c7e0e074472c46f55716267225f4fd6;p=gostls13.git bytes, strings: declare variables inside loop they're used in 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 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/bytes/bytes.go b/src/bytes/bytes.go index de3bd0515a..7c878af688 100644 --- a/src/bytes/bytes.go +++ b/src/bytes/bytes.go @@ -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 { diff --git a/src/strings/strings.go b/src/strings/strings.go index 9ca222fdfa..2650fb057c 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -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 {