MCPcopy
hub / github.com/duke-git/lancet / compareRefValue

Function compareRefValue

compare/compare_internal.go:40–119  ·  view source on GitHub ↗
(operator string, leftObj, rightObj any, kind reflect.Kind)

Source from the content-addressed store, hash-verified

38}
39
40func compareRefValue(operator string, leftObj, rightObj any, kind reflect.Kind) bool {
41 leftVal, rightVal := reflect.ValueOf(leftObj), reflect.ValueOf(rightObj)
42
43 switch kind {
44 case reflect.Struct:
45
46 // compare time
47 if leftVal.CanConvert(timeType) {
48 timeObj1, ok := leftObj.(time.Time)
49 if !ok {
50 timeObj1 = leftVal.Convert(timeType).Interface().(time.Time)
51 }
52
53 timeObj2, ok := rightObj.(time.Time)
54 if !ok {
55 timeObj2 = rightVal.Convert(timeType).Interface().(time.Time)
56 }
57
58 return compareBasicValue(operator, timeObj1.UnixNano(), timeObj2.UnixNano())
59 }
60
61 // for other struct type, only process equal operator
62 switch operator {
63 case equal:
64 return objectsAreEqualValues(leftObj, rightObj)
65 }
66
67 case reflect.Slice:
68 // compare []byte
69 if leftVal.CanConvert(bytesType) {
70 bytesObj1, ok := leftObj.([]byte)
71 if !ok {
72 bytesObj1 = leftVal.Convert(bytesType).Interface().([]byte)
73 }
74 bytesObj2, ok := rightObj.([]byte)
75 if !ok {
76 bytesObj2 = rightVal.Convert(bytesType).Interface().([]byte)
77 }
78
79 switch operator {
80 case equal:
81 if bytes.Equal(bytesObj1, bytesObj2) {
82 return true
83 }
84 case lessThan:
85 if bytes.Compare(bytesObj1, bytesObj2) == -1 {
86 return true
87 }
88 case greaterThan:
89 if bytes.Compare(bytesObj1, bytesObj2) == 1 {
90 return true
91 }
92 case lessOrEqual:
93 if bytes.Compare(bytesObj1, bytesObj2) <= 0 {
94 return true
95 }
96 case greaterOrEqual:
97 if bytes.Compare(bytesObj1, bytesObj2) >= 0 {

Callers 1

compareValueFunction · 0.85

Calls 5

compareBasicValueFunction · 0.85
objectsAreEqualValuesFunction · 0.70
CompareMethod · 0.65
ValueOfMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…