upb: add 'options' arg to upb_Message_IsEqual()
PiperOrigin-RevId: 614707625pull/16086/head
parent
bb1c0abcbf
commit
e1a19ba8bb
|
@ -271,9 +271,9 @@ bool PyUpb_PyToUpb(PyObject* obj, const upb_FieldDef* f, upb_MessageValue* val,
|
|||
}
|
||||
|
||||
bool upb_Message_IsEqualByDef(const upb_Message* msg1, const upb_Message* msg2,
|
||||
const upb_MessageDef* msgdef) {
|
||||
const upb_MessageDef* msgdef, int options) {
|
||||
const upb_MiniTable* m = upb_MessageDef_MiniTable(msgdef);
|
||||
return upb_Message_IsEqual(msg1, msg2, m);
|
||||
return upb_Message_IsEqual(msg1, msg2, m, options);
|
||||
}
|
||||
|
||||
#include "upb/port/undef.inc"
|
||||
|
|
|
@ -30,6 +30,6 @@ bool PyUpb_PyToUpb(PyObject* obj, const upb_FieldDef* f, upb_MessageValue* val,
|
|||
|
||||
// Returns true if the given messages (of type `m`) are equal.
|
||||
bool upb_Message_IsEqualByDef(const upb_Message* msg1, const upb_Message* msg2,
|
||||
const upb_MessageDef* msgdef);
|
||||
const upb_MessageDef* msgdef, int options);
|
||||
|
||||
#endif // PYUPB_CONVERT_H__
|
||||
|
|
|
@ -197,7 +197,8 @@ static PyObject* PyUpb_DescriptorPool_DoAddSerializedFile(
|
|||
goto done;
|
||||
}
|
||||
const upb_MessageDef* m = PyUpb_DescriptorPool_GetFileProtoDef();
|
||||
if (upb_Message_IsEqualByDef(UPB_UPCAST(proto), UPB_UPCAST(existing), m)) {
|
||||
if (upb_Message_IsEqualByDef(UPB_UPCAST(proto), UPB_UPCAST(existing), m,
|
||||
/*options=*/0)) {
|
||||
result = PyUpb_FileDescriptor_Get(file);
|
||||
goto done;
|
||||
}
|
||||
|
|
|
@ -575,7 +575,7 @@ static bool PyUpb_Message_IsEqual(PyUpb_Message* m1, PyObject* _m2) {
|
|||
const bool e2 = PyUpb_Message_IsEmpty(m2_msg, m1_msgdef, symtab);
|
||||
if (e1 || e2) return e1 && e2;
|
||||
|
||||
return upb_Message_IsEqualByDef(m1_msg, m2_msg, m1_msgdef);
|
||||
return upb_Message_IsEqualByDef(m1_msg, m2_msg, m1_msgdef, 0);
|
||||
}
|
||||
|
||||
static const upb_FieldDef* PyUpb_Message_InitAsMsg(PyUpb_Message* m,
|
||||
|
|
|
@ -96,7 +96,8 @@ bool upb_Message_IsEmpty(const upb_Message* msg, const upb_MiniTable* m) {
|
|||
}
|
||||
|
||||
static bool _upb_Array_IsEqual(const upb_Array* arr1, const upb_Array* arr2,
|
||||
upb_CType ctype, const upb_MiniTable* m) {
|
||||
upb_CType ctype, const upb_MiniTable* m,
|
||||
int options) {
|
||||
// Check for trivial equality.
|
||||
if (arr1 == arr2) return true;
|
||||
|
||||
|
@ -109,14 +110,14 @@ static bool _upb_Array_IsEqual(const upb_Array* arr1, const upb_Array* arr2,
|
|||
const upb_MessageValue val1 = upb_Array_Get(arr1, i);
|
||||
const upb_MessageValue val2 = upb_Array_Get(arr2, i);
|
||||
|
||||
if (!upb_MessageValue_IsEqual(val1, val2, ctype, m)) return false;
|
||||
if (!upb_MessageValue_IsEqual(val1, val2, ctype, m, options)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool _upb_Map_IsEqual(const upb_Map* map1, const upb_Map* map2,
|
||||
const upb_MiniTable* m) {
|
||||
const upb_MiniTable* m, int options) {
|
||||
// Check for trivial equality.
|
||||
if (map1 == map2) return true;
|
||||
|
||||
|
@ -133,7 +134,8 @@ static bool _upb_Map_IsEqual(const upb_Map* map1, const upb_Map* map2,
|
|||
size_t iter = kUpb_Map_Begin;
|
||||
while (upb_Map_Next(map1, &key, &val1, &iter)) {
|
||||
if (!upb_Map_Get(map2, key, &val2)) return false;
|
||||
if (!upb_MessageValue_IsEqual(val1, val2, ctype, m2_value)) return false;
|
||||
if (!upb_MessageValue_IsEqual(val1, val2, ctype, m2_value, options))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -141,7 +143,8 @@ static bool _upb_Map_IsEqual(const upb_Map* map1, const upb_Map* map2,
|
|||
|
||||
static bool _upb_Message_BaseFieldsAreEqual(const upb_Message* msg1,
|
||||
const upb_Message* msg2,
|
||||
const upb_MiniTable* m) {
|
||||
const upb_MiniTable* m,
|
||||
int options) {
|
||||
// Iterate over all base fields for each message.
|
||||
// The order will always match if the messages are equal.
|
||||
size_t iter1 = kUpb_BaseField_Begin;
|
||||
|
@ -164,13 +167,14 @@ static bool _upb_Message_BaseFieldsAreEqual(const upb_Message* msg1,
|
|||
bool eq;
|
||||
switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(f1)) {
|
||||
case kUpb_FieldMode_Array:
|
||||
eq = _upb_Array_IsEqual(val1.array_val, val2.array_val, ctype, subm);
|
||||
eq = _upb_Array_IsEqual(val1.array_val, val2.array_val, ctype, subm,
|
||||
options);
|
||||
break;
|
||||
case kUpb_FieldMode_Map:
|
||||
eq = _upb_Map_IsEqual(val1.map_val, val2.map_val, subm);
|
||||
eq = _upb_Map_IsEqual(val1.map_val, val2.map_val, subm, options);
|
||||
break;
|
||||
case kUpb_FieldMode_Scalar:
|
||||
eq = upb_MessageValue_IsEqual(val1, val2, ctype, subm);
|
||||
eq = upb_MessageValue_IsEqual(val1, val2, ctype, subm, options);
|
||||
break;
|
||||
}
|
||||
if (!eq) return false;
|
||||
|
@ -179,7 +183,8 @@ static bool _upb_Message_BaseFieldsAreEqual(const upb_Message* msg1,
|
|||
|
||||
static bool _upb_Message_ExtensionsAreEqual(const upb_Message* msg1,
|
||||
const upb_Message* msg2,
|
||||
const upb_MiniTable* m) {
|
||||
const upb_MiniTable* m,
|
||||
int options) {
|
||||
// Must have identical extension counts.
|
||||
if (upb_Message_ExtensionCount(msg1) != upb_Message_ExtensionCount(msg2)) {
|
||||
return false;
|
||||
|
@ -204,13 +209,14 @@ static bool _upb_Message_ExtensionsAreEqual(const upb_Message* msg1,
|
|||
bool eq;
|
||||
switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(f)) {
|
||||
case kUpb_FieldMode_Array:
|
||||
eq = _upb_Array_IsEqual(val1.array_val, val2.array_val, ctype, subm);
|
||||
eq = _upb_Array_IsEqual(val1.array_val, val2.array_val, ctype, subm,
|
||||
options);
|
||||
break;
|
||||
case kUpb_FieldMode_Map:
|
||||
UPB_UNREACHABLE(); // Maps cannot be extensions.
|
||||
break;
|
||||
case kUpb_FieldMode_Scalar: {
|
||||
eq = upb_MessageValue_IsEqual(val1, val2, ctype, subm);
|
||||
eq = upb_MessageValue_IsEqual(val1, val2, ctype, subm, options);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -220,11 +226,11 @@ static bool _upb_Message_ExtensionsAreEqual(const upb_Message* msg1,
|
|||
}
|
||||
|
||||
bool upb_Message_IsEqual(const upb_Message* msg1, const upb_Message* msg2,
|
||||
const upb_MiniTable* m) {
|
||||
const upb_MiniTable* m, int options) {
|
||||
if (UPB_UNLIKELY(msg1 == msg2)) return true;
|
||||
|
||||
if (!_upb_Message_BaseFieldsAreEqual(msg1, msg2, m)) return false;
|
||||
if (!_upb_Message_ExtensionsAreEqual(msg1, msg2, m)) return false;
|
||||
if (!_upb_Message_BaseFieldsAreEqual(msg1, msg2, m, options)) return false;
|
||||
if (!_upb_Message_ExtensionsAreEqual(msg1, msg2, m, options)) return false;
|
||||
|
||||
// Check the unknown fields.
|
||||
size_t usize1, usize2;
|
||||
|
|
|
@ -30,13 +30,14 @@ UPB_API bool upb_Message_IsEmpty(const upb_Message* msg,
|
|||
|
||||
UPB_API bool upb_Message_IsEqual(const upb_Message* msg1,
|
||||
const upb_Message* msg2,
|
||||
const upb_MiniTable* m);
|
||||
const upb_MiniTable* m, int options);
|
||||
|
||||
// If |ctype| is a message then |m| must point to its minitable.
|
||||
UPB_API_INLINE bool upb_MessageValue_IsEqual(upb_MessageValue val1,
|
||||
upb_MessageValue val2,
|
||||
upb_CType ctype,
|
||||
const upb_MiniTable* m) {
|
||||
const upb_MiniTable* m,
|
||||
int options) {
|
||||
switch (ctype) {
|
||||
case kUpb_CType_Bool:
|
||||
return val1.bool_val == val2.bool_val;
|
||||
|
@ -57,7 +58,7 @@ UPB_API_INLINE bool upb_MessageValue_IsEqual(upb_MessageValue val1,
|
|||
return upb_StringView_IsEqual(val1.str_val, val2.str_val);
|
||||
|
||||
case kUpb_CType_Message:
|
||||
return upb_Message_IsEqual(val1.msg_val, val2.msg_val, m);
|
||||
return upb_Message_IsEqual(val1.msg_val, val2.msg_val, m, options);
|
||||
|
||||
default:
|
||||
UPB_UNREACHABLE();
|
||||
|
|
Loading…
Reference in New Issue