]> Cypherpunks.ru repositories - gostls13.git/commitdiff
reflect: simplify Value.Comparable
authorcuiweixie <cuiweixie@gmail.com>
Mon, 29 Aug 2022 17:30:53 +0000 (01:30 +0800)
committerGopher Robot <gobot@golang.org>
Mon, 26 Sep 2022 16:36:07 +0000 (16:36 +0000)
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>

src/reflect/value.go

index 4456fdc5a57450f479019d14cf425e161a9a4fab..ae6c4daf587b4baad6219aa3be86bca5f54afbe2 100644 (file)
@@ -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()
        }
 }