aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json/encode.go
diff options
context:
space:
mode:
authorDaniel Martí <mvdan@mvdan.cc>2019-03-05 20:44:29 +0000
committerDaniel Martí <mvdan@mvdan.cc>2019-03-08 14:29:19 +0000
commit49662bc6b02810389c66b6b24576f6a5b217d471 (patch)
tree15769762bf84bad2b9f1a4a1181845a5ad0673f5 /src/encoding/json/encode.go
parentce7534ff06df5b3148aa325deedcb94ac5b30ec0 (diff)
downloadgo-49662bc6b02810389c66b6b24576f6a5b217d471.tar.xz
all: simplify multiple for loops
If a for loop has a simple condition and begins with a simple "if x { break; }"; we can simply add "!x" to the loop's condition. While at it, simplify a few assignments to use the common pattern "x := staticDefault; if cond { x = otherValue(); }". Finally, simplify a couple of var declarations. Change-Id: I413982c6abd32905adc85a9a666cb3819139c19f Reviewed-on: https://go-review.googlesource.com/c/go/+/165342 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/encoding/json/encode.go')
-rw-r--r--src/encoding/json/encode.go3
1 files changed, 1 insertions, 2 deletions
diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go
index de6d2632f4..e3c5ffc9cb 100644
--- a/src/encoding/json/encode.go
+++ b/src/encoding/json/encode.go
@@ -1069,8 +1069,7 @@ func typeFields(t reflect.Type) []field {
next := []field{{typ: t}}
// Count of queued names for current level and the next.
- count := map[reflect.Type]int{}
- nextCount := map[reflect.Type]int{}
+ var count, nextCount map[reflect.Type]int
// Types already visited at an earlier level.
visited := map[reflect.Type]bool{}