mirror of
https://github.com/golang/go
synced 2024-11-17 23:04:56 -07:00
reflect: simplify Value.Comparable
using Type.Comparable to simplify the Value.Comparable, and return true directly when exit the for loop of kind == array and elements type is interface or array or struct. Change-Id: Ib0b06a70642ba24c9215c69e7d619960fbeeed90 Reviewed-on: https://go-review.googlesource.com/c/go/+/426457 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: xie cui <523516579@qq.com>
This commit is contained in:
parent
deaec39323
commit
c3728b7502
@ -3270,14 +3270,6 @@ func (v Value) Comparable() bool {
|
||||
case Invalid:
|
||||
return false
|
||||
|
||||
case Bool,
|
||||
Int, Int8, Int16, Int32, Int64,
|
||||
Uint, Uint8, Uint16, Uint32, Uint64,
|
||||
Uintptr,
|
||||
Float32, Float64, Complex64, Complex128,
|
||||
Chan:
|
||||
return true
|
||||
|
||||
case Array:
|
||||
switch v.Type().Elem().Kind() {
|
||||
case Interface, Array, Struct:
|
||||
@ -3286,27 +3278,13 @@ func (v Value) Comparable() bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
return v.Type().Comparable()
|
||||
|
||||
case Func:
|
||||
return false
|
||||
|
||||
case Interface:
|
||||
return v.Elem().Comparable()
|
||||
|
||||
case Map:
|
||||
return false
|
||||
|
||||
case Pointer:
|
||||
return true
|
||||
|
||||
case Slice:
|
||||
return false
|
||||
|
||||
case String:
|
||||
return true
|
||||
|
||||
case Struct:
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
if !v.Field(i).Comparable() {
|
||||
@ -3315,11 +3293,8 @@ func (v Value) Comparable() bool {
|
||||
}
|
||||
return true
|
||||
|
||||
case UnsafePointer:
|
||||
return true
|
||||
|
||||
default:
|
||||
return false
|
||||
return v.Type().Comparable()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user