aboutsummaryrefslogtreecommitdiff
path: root/cmp
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2017-11-29 14:34:42 -0800
committerJoe Tsai <joetsai@digital-static.net>2017-11-29 14:34:42 -0800
commit2cfd585f7b0d542f04e00d763eadd64dfe6abd3e (patch)
tree0133a1f8a4aa30680a3815c54e6712f3f7fb7c86 /cmp
parent3f298f31d5756f2fe00ddfbeda978125ad24862e (diff)
downloadgo-cmp-2cfd585f7b0d542f04e00d763eadd64dfe6abd3e.tar.gz
Remove useless return value from apply
For all implementations of apply, it either returns true or panics. Thus, the bool return value is a useless piece of information. Simplify the interface by removing the return value.
Diffstat (limited to 'cmp')
-rw-r--r--cmp/compare.go3
-rw-r--r--cmp/options.go17
2 files changed, 9 insertions, 11 deletions
diff --git a/cmp/compare.go b/cmp/compare.go
index b180917..143407c 100644
--- a/cmp/compare.go
+++ b/cmp/compare.go
@@ -304,7 +304,8 @@ func (s *state) tryOptions(vx, vy reflect.Value, t reflect.Type) bool {
// Evaluate all filters and apply the remaining options.
if opt := opts.filter(s, vx, vy, t); opt != nil {
- return opt.apply(s, vx, vy)
+ opt.apply(s, vx, vy)
+ return true
}
return false
}
diff --git a/cmp/options.go b/cmp/options.go
index c19fbc7..885efc8 100644
--- a/cmp/options.go
+++ b/cmp/options.go
@@ -38,9 +38,8 @@ type Option interface {
type applicableOption interface {
Option
- // apply executes the option and reports whether the option was applied.
- // Each option may mutate s.
- apply(s *state, vx, vy reflect.Value) bool
+ // apply executes the option, which may mutate s or panic.
+ apply(s *state, vx, vy reflect.Value)
}
// coreOption represents the following types:
@@ -85,7 +84,7 @@ func (opts Options) filter(s *state, vx, vy reflect.Value, t reflect.Type) (out
return out
}
-func (opts Options) apply(s *state, _, _ reflect.Value) bool {
+func (opts Options) apply(s *state, _, _ reflect.Value) {
const warning = "ambiguous set of applicable options"
const help = "consider using filters to ensure at most one Comparer or Transformer may apply"
var ss []string
@@ -196,7 +195,7 @@ type ignore struct{ core }
func (ignore) isFiltered() bool { return false }
func (ignore) filter(_ *state, _, _ reflect.Value, _ reflect.Type) applicableOption { return ignore{} }
-func (ignore) apply(_ *state, _, _ reflect.Value) bool { return true }
+func (ignore) apply(_ *state, _, _ reflect.Value) { return }
func (ignore) String() string { return "Ignore()" }
// invalid is a sentinel Option type to indicate that some options could not
@@ -204,7 +203,7 @@ func (ignore) String() string
type invalid struct{ core }
func (invalid) filter(_ *state, _, _ reflect.Value, _ reflect.Type) applicableOption { return invalid{} }
-func (invalid) apply(s *state, _, _ reflect.Value) bool {
+func (invalid) apply(s *state, _, _ reflect.Value) {
const help = "consider using AllowUnexported or cmpopts.IgnoreUnexported"
panic(fmt.Sprintf("cannot handle unexported field: %#v\n%s", s.curPath, help))
}
@@ -265,7 +264,7 @@ func (tr *transformer) filter(s *state, _, _ reflect.Value, t reflect.Type) appl
return nil
}
-func (tr *transformer) apply(s *state, vx, vy reflect.Value) bool {
+func (tr *transformer) apply(s *state, vx, vy reflect.Value) {
// Update path before calling the Transformer so that dynamic checks
// will use the updated path.
s.curPath.push(&transform{pathStep{tr.fnc.Type().Out(0)}, tr})
@@ -274,7 +273,6 @@ func (tr *transformer) apply(s *state, vx, vy reflect.Value) bool {
vx = s.callTRFunc(tr.fnc, vx)
vy = s.callTRFunc(tr.fnc, vy)
s.compareAny(vx, vy)
- return true
}
func (tr transformer) String() string {
@@ -320,10 +318,9 @@ func (cm *comparer) filter(_ *state, _, _ reflect.Value, t reflect.Type) applica
return nil
}
-func (cm *comparer) apply(s *state, vx, vy reflect.Value) bool {
+func (cm *comparer) apply(s *state, vx, vy reflect.Value) {
eq := s.callTTBFunc(cm.fnc, vx, vy)
s.report(eq, vx, vy)
- return true
}
func (cm comparer) String() string {