From 59f6549d1c7e0e074472c46f55716267225f4fd6 Mon Sep 17 00:00:00 2001 From: Eric Lagergren Date: Mon, 3 Apr 2017 16:08:13 -0700 Subject: [PATCH] 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 --- src/bytes/bytes.go | 2 +- src/strings/strings.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 { -- 2.48.1