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

Method RepeatedFieldEquals

internal/message_equality.cc:942–981  ·  view source on GitHub ↗

Equality between repeated message fields.

Source from the content-addressed store, hash-verified

940
941 // Equality between repeated message fields.
942 absl::StatusOr<bool> RepeatedFieldEquals(
943 const Message& lhs, const FieldDescriptor* absl_nonnull lhs_field,
944 const Message& rhs, const FieldDescriptor* absl_nonnull rhs_field) {
945 ABSL_DCHECK(lhs_field->is_repeated() && !lhs_field->is_map());
946 ABSL_DCHECK_EQ(lhs_field->containing_type(), lhs.GetDescriptor());
947 ABSL_DCHECK(rhs_field->is_repeated() && !rhs_field->is_map());
948 ABSL_DCHECK_EQ(rhs_field->containing_type(), rhs.GetDescriptor());
949 // Perform cheap test which checks whether the left and right can even be
950 // compared for equality.
951 if (lhs_field != rhs_field &&
952 (GetEquatableFieldCategory(lhs_field) &
953 GetEquatableFieldCategory(rhs_field)) == EquatableCategory::kNone) {
954 // Short-circuit.
955 return false;
956 }
957 const auto* lhs_reflection = lhs.GetReflection();
958 const auto* rhs_reflection = rhs.GetReflection();
959 const auto size = lhs_reflection->FieldSize(lhs, lhs_field);
960 if (size != rhs_reflection->FieldSize(rhs, rhs_field)) {
961 return false;
962 }
963 Unique<Message> lhs_unpacked;
964 EquatableValue lhs_value;
965 Unique<Message> rhs_unpacked;
966 EquatableValue rhs_value;
967 for (int i = 0; i < size; ++i) {
968 CEL_ASSIGN_OR_RETURN(lhs_value,
969 RepeatedFieldAsEquatableValue(
970 &arena_, pool_, factory_, lhs_reflection_, lhs,
971 lhs_field, i, lhs_scratch_, lhs_unpacked));
972 CEL_ASSIGN_OR_RETURN(rhs_value,
973 RepeatedFieldAsEquatableValue(
974 &arena_, pool_, factory_, rhs_reflection_, rhs,
975 rhs_field, i, rhs_scratch_, rhs_unpacked));
976 if (!EquatableValueEquals(lhs_value, rhs_value)) {
977 return false;
978 }
979 }
980 return true;
981 }
982
983 // Equality between singular message fields and/or messages. If the field is
984 // `nullptr`, we are performing equality on the message itself rather than the

Callers

nothing calls this directly

Calls 6

EquatableValueEqualsFunction · 0.85
CEL_ASSIGN_OR_RETURNFunction · 0.50
GetDescriptorMethod · 0.45
GetReflectionMethod · 0.45

Tested by

no test coverage detected