Skip to content

Commit

Permalink
Use reflect.Value.IsZero (#297)
Browse files Browse the repository at this point in the history
Now that Go 1.13 is the minimum version, we can use the reflect.Value.IsZero
method instead of our own internal/value.IsZero function.
Interestingly, our IsZero function pre-dates the IsZero method,
but fortunately has the exact same semantics, since both are targetting
semantics defined by the Go language specification.
  • Loading branch information
dsnet authored Jun 6, 2022
1 parent f144a35 commit a53d7e0
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 106 deletions.
48 changes: 0 additions & 48 deletions cmp/internal/value/zero.go

This file was deleted.

52 changes: 0 additions & 52 deletions cmp/internal/value/zero_test.go

This file was deleted.

8 changes: 3 additions & 5 deletions cmp/report_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ package cmp
import (
"fmt"
"reflect"

"github.com/google/go-cmp/cmp/internal/value"
)

// numContextRecords is the number of surrounding equal records to print.
Expand Down Expand Up @@ -248,11 +246,11 @@ func (opts formatOptions) formatDiffList(recs []reportRecord, k reflect.Kind, pt
var isZero bool
switch opts.DiffMode {
case diffIdentical:
isZero = value.IsZero(r.Value.ValueX) || value.IsZero(r.Value.ValueY)
isZero = r.Value.ValueX.IsZero() || r.Value.ValueY.IsZero()
case diffRemoved:
isZero = value.IsZero(r.Value.ValueX)
isZero = r.Value.ValueX.IsZero()
case diffInserted:
isZero = value.IsZero(r.Value.ValueY)
isZero = r.Value.ValueY.IsZero()
}
if isZero {
continue
Expand Down
2 changes: 1 addition & 1 deletion cmp/report_reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (opts formatOptions) FormatValue(v reflect.Value, parentKind reflect.Kind,
}
for i := 0; i < v.NumField(); i++ {
vv := v.Field(i)
if value.IsZero(vv) {
if vv.IsZero() {
continue // Elide fields with zero values
}
if len(list) == maxLen {
Expand Down

0 comments on commit a53d7e0

Please sign in to comment.