Skip to content

Commit

Permalink
all: simplify multiple for loops
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mvdan committed Mar 8, 2019
1 parent 4f1e17a commit ae5e45e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
2 changes: 1 addition & 1 deletion stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{
Expand Down

0 comments on commit ae5e45e

Please sign in to comment.