Skip to content

Commit

Permalink
reflect: simplify array value comparable check
Browse files Browse the repository at this point in the history
If array element is not interface, array or struct, we just need to
check whether the array element type is comparable.

Change-Id: I1ab94cfa17ae86feb6cd3fbdf878af5a776e7bec
Reviewed-on: https://go-review.googlesource.com/c/go/+/426194
Reviewed-by: Cherry Mui <[email protected]>
Run-TryBot: Cuong Manh Le <[email protected]>
Auto-Submit: Cuong Manh Le <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
  • Loading branch information
cuonglm authored and gopherbot committed Aug 29, 2022
1 parent 63e129b commit 7393049
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions src/reflect/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -3264,22 +3264,15 @@ func (v Value) Comparable() bool {
return true

case Array:
if v.Type().Len() == 0 {
return v.Type().Comparable()
}

switch v.Type().Elem().Kind() {
case Interface, Array, Struct:
for i := 0; i < v.Type().Len(); i++ {
if !v.Index(i).Comparable() {
return false
}
}
default:
return v.Index(0).Comparable()
}

return true
return v.Type().Comparable()

case Func:
return false
Expand Down

0 comments on commit 7393049

Please sign in to comment.