MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / Compare

Method Compare

pkg/util/json/json.go:723–760  ·  view source on GitHub ↗
(other JSON)

Source from the content-addressed store, hash-verified

721}
722
723func (j jsonArray) Compare(other JSON) (int, error) {
724 switch {
725 case isEmptyArray(j) && isEmptyArray(other):
726 return 0, nil
727 case isEmptyArray(j):
728 return -1, nil
729 case isEmptyArray(other):
730 return 1, nil
731 }
732 cmp := cmpJSONTypes(j.Type(), other.Type())
733 if cmp != 0 {
734 return cmp, nil
735 }
736 lenJ := j.Len()
737 lenO := other.Len()
738 if lenJ < lenO {
739 return -1, nil
740 }
741 if lenJ > lenO {
742 return 1, nil
743 }
744 // TODO(justin): we should optimize this, we don't have to decode the whole thing.
745 var err error
746 if other, err = decodeIfNeeded(other); err != nil {
747 return 0, err
748 }
749 o := other.(jsonArray)
750 for i := 0; i < lenJ; i++ {
751 cmp, err := j[i].Compare(o[i])
752 if err != nil {
753 return 0, err
754 }
755 if cmp != 0 {
756 return cmp, nil
757 }
758 }
759 return 0, nil
760}
761
762func (j jsonObject) Compare(other JSON) (int, error) {
763 // NOTE: There is no need to check if other is an empty array because all

Callers

nothing calls this directly

Calls 8

TypeMethod · 0.95
LenMethod · 0.95
isEmptyArrayFunction · 0.85
cmpJSONTypesFunction · 0.85
decodeIfNeededFunction · 0.85
TypeMethod · 0.65
LenMethod · 0.65
CompareMethod · 0.65

Tested by

no test coverage detected