aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json
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
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')
-rw-r--r--src/encoding/json/encode.go3
-rw-r--r--src/encoding/json/stream_test.go2
2 files changed, 2 insertions, 3 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{}
diff --git a/src/encoding/json/stream_test.go b/src/encoding/json/stream_test.go
index aaf32e0a24..8dc74e5466 100644
--- a/src/encoding/json/stream_test.go
+++ b/src/encoding/json/stream_test.go
@@ -296,7 +296,7 @@ type decodeThis struct {
v interface{}
}
-var tokenStreamCases []tokenStreamCase = []tokenStreamCase{
+var tokenStreamCases = []tokenStreamCase{
// streaming token cases
{json: `10`, expTokens: []interface{}{float64(10)}},
{json: ` [10] `, expTokens: []interface{}{