]> Cypherpunks.ru repositories - gostls13.git/commitdiff
reflect: simplify array value comparable check
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Sat, 27 Aug 2022 14:38:45 +0000 (21:38 +0700)
committerGopher Robot <gobot@golang.org>
Mon, 29 Aug 2022 16:39:37 +0000 (16:39 +0000)
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 <cherryyz@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/reflect/value.go

index 9c8b82c41e5816116b863f342675a6625e09e469..061545bd4f09acdee614703089dd54e729dbe891 100644 (file)
@@ -3264,10 +3264,6 @@ 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++ {
@@ -3275,11 +3271,8 @@ func (v Value) Comparable() bool {
                                        return false
                                }
                        }
-               default:
-                       return v.Index(0).Comparable()
                }
-
-               return true
+               return v.Type().Comparable()
 
        case Func:
                return false