MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / SingularFieldEquals

Method SingularFieldEquals

internal/message_equality.cc:986–1071  ·  view source on GitHub ↗

Equality between singular message fields and/or messages. If the field is `nullptr`, we are performing equality on the message itself rather than the corresponding field.

Source from the content-addressed store, hash-verified

984 // `nullptr`, we are performing equality on the message itself rather than the
985 // corresponding field.
986 absl::StatusOr<bool> SingularFieldEquals(
987 const Message& lhs, const FieldDescriptor* absl_nullable lhs_field,
988 const Message& rhs, const FieldDescriptor* absl_nullable rhs_field) {
989 ABSL_DCHECK(lhs_field == nullptr ||
990 (!lhs_field->is_repeated() && !lhs_field->is_map()));
991 ABSL_DCHECK(lhs_field == nullptr ||
992 lhs_field->containing_type() == lhs.GetDescriptor());
993 ABSL_DCHECK(rhs_field == nullptr ||
994 (!rhs_field->is_repeated() && !rhs_field->is_map()));
995 ABSL_DCHECK(rhs_field == nullptr ||
996 rhs_field->containing_type() == rhs.GetDescriptor());
997 // Perform cheap test which checks whether the left and right can even be
998 // compared for equality.
999 if (lhs_field != rhs_field &&
1000 ((lhs_field != nullptr ? GetEquatableFieldCategory(lhs_field)
1001 : GetEquatableCategory(lhs.GetDescriptor())) &
1002 (rhs_field != nullptr ? GetEquatableFieldCategory(rhs_field)
1003 : GetEquatableCategory(rhs.GetDescriptor()))) ==
1004 EquatableCategory::kNone) {
1005 // Short-circuit.
1006 return false;
1007 }
1008 const Message* absl_nonnull lhs_ptr = &lhs;
1009 const Message* absl_nonnull rhs_ptr = &rhs;
1010 Unique<Message> lhs_unpacked;
1011 Unique<Message> rhs_unpacked;
1012 if (lhs_field != nullptr && IsAnyField(lhs_field)) {
1013 CEL_ASSIGN_OR_RETURN(lhs_unpacked,
1014 well_known_types::UnpackAnyIfResolveable(
1015 &arena_, lhs_reflection_.any_reflection,
1016 lhs.GetReflection()->GetMessage(lhs, lhs_field),
1017 pool_, factory_));
1018 if (lhs_unpacked) {
1019 lhs_ptr = cel::to_address(lhs_unpacked);
1020 lhs_field = nullptr;
1021 }
1022 } else if (lhs_field == nullptr && IsAny(lhs)) {
1023 CEL_ASSIGN_OR_RETURN(
1024 lhs_unpacked,
1025 well_known_types::UnpackAnyIfResolveable(
1026 &arena_, lhs_reflection_.any_reflection, lhs, pool_, factory_));
1027 if (lhs_unpacked) {
1028 lhs_ptr = cel::to_address(lhs_unpacked);
1029 }
1030 }
1031 if (rhs_field != nullptr && IsAnyField(rhs_field)) {
1032 CEL_ASSIGN_OR_RETURN(rhs_unpacked,
1033 well_known_types::UnpackAnyIfResolveable(
1034 &arena_, rhs_reflection_.any_reflection,
1035 rhs.GetReflection()->GetMessage(rhs, rhs_field),
1036 pool_, factory_));
1037 if (rhs_unpacked) {
1038 rhs_ptr = cel::to_address(rhs_unpacked);
1039 rhs_field = nullptr;
1040 }
1041 } else if (rhs_field == nullptr && IsAny(rhs)) {
1042 CEL_ASSIGN_OR_RETURN(
1043 rhs_unpacked,

Callers

nothing calls this directly

Calls 12

GetEquatableCategoryFunction · 0.85
IsAnyFieldFunction · 0.85
UnpackAnyIfResolveableFunction · 0.85
to_addressFunction · 0.85
IsAnyFunction · 0.85
AsEquatableValueFunction · 0.85
EquatableValueEqualsFunction · 0.85
CEL_ASSIGN_OR_RETURNFunction · 0.50
GetDescriptorMethod · 0.45
GetMessageMethod · 0.45
GetReflectionMethod · 0.45

Tested by

no test coverage detected