MCPcopy
hub / github.com/tinygo-org/tinygo / reflectValueEqual

Function reflectValueEqual

src/runtime/interface.go:33–83  ·  view source on GitHub ↗
(x, y reflectlite.Value)

Source from the content-addressed store, hash-verified

31}
32
33func reflectValueEqual(x, y reflectlite.Value) bool {
34 // Note: doing a x.Type() == y.Type() comparison would not work here as that
35 // would introduce an infinite recursion: comparing two reflectlite.Type values
36 // is done with this reflectValueEqual runtime call.
37 if x.RawType() == nil || y.RawType() == nil {
38 // One of them is nil.
39 return x.RawType() == y.RawType()
40 }
41
42 if x.RawType() != y.RawType() {
43 // The type is not the same, which means the interfaces are definitely
44 // not the same.
45 return false
46 }
47
48 switch x.RawType().Kind() {
49 case reflectlite.Bool:
50 return x.Bool() == y.Bool()
51 case reflectlite.Int, reflectlite.Int8, reflectlite.Int16, reflectlite.Int32, reflectlite.Int64:
52 return x.Int() == y.Int()
53 case reflectlite.Uint, reflectlite.Uint8, reflectlite.Uint16, reflectlite.Uint32, reflectlite.Uint64, reflectlite.Uintptr:
54 return x.Uint() == y.Uint()
55 case reflectlite.Float32, reflectlite.Float64:
56 return x.Float() == y.Float()
57 case reflectlite.Complex64, reflectlite.Complex128:
58 return x.Complex() == y.Complex()
59 case reflectlite.String:
60 return x.String() == y.String()
61 case reflectlite.Chan, reflectlite.Ptr, reflectlite.UnsafePointer:
62 return x.UnsafePointer() == y.UnsafePointer()
63 case reflectlite.Array:
64 for i := 0; i < x.Len(); i++ {
65 if !reflectValueEqual(x.Index(i), y.Index(i)) {
66 return false
67 }
68 }
69 return true
70 case reflectlite.Struct:
71 for i := 0; i < x.NumField(); i++ {
72 if !reflectValueEqual(x.Field(i), y.Field(i)) {
73 return false
74 }
75 }
76 return true
77 case reflectlite.Interface:
78 return reflectValueEqual(x.Elem(), y.Elem())
79 default:
80 runtimePanic("comparing un-comparable type")
81 return false // unreachable
82 }
83}
84
85// interfaceTypeAssert is called when a type assert without comma-ok still
86// returns false.

Callers 1

interfaceEqualFunction · 0.85

Calls 15

RawTypeMethod · 0.80
BoolMethod · 0.80
FloatMethod · 0.80
ComplexMethod · 0.80
UnsafePointerMethod · 0.80
runtimePanicFunction · 0.70
KindMethod · 0.65
IntMethod · 0.65
UintMethod · 0.65
StringMethod · 0.65
LenMethod · 0.65
NumFieldMethod · 0.65

Tested by

no test coverage detected