Skip to content

Commit 0afb41a

Browse files
CEL Dev Teamcopybara-github
authored andcommitted
Use proto2::ConstMapIterator and stop const_cast'ing.
PiperOrigin-RevId: 897931899
1 parent 7022451 commit 0afb41a

File tree

8 files changed

+59
-64
lines changed

8 files changed

+59
-64
lines changed

common/values/parsed_json_map_value.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ class ParsedJsonMapValueIterator final : public ValueIterator {
408408
private:
409409
const google::protobuf::Message* absl_nonnull const message_;
410410
const well_known_types::StructReflection reflection_;
411-
google::protobuf::MapIterator begin_;
412-
const google::protobuf::MapIterator end_;
411+
proto2::ConstMapIterator begin_;
412+
const proto2::ConstMapIterator end_;
413413
std::string scratch_;
414414
};
415415

common/values/parsed_map_field_value.cc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,10 @@ absl::Status ParsedMapFieldValue::ListKeys(
415415
field_->message_type()->map_key()));
416416
auto builder = NewListValueBuilder(arena);
417417
builder->Reserve(Size());
418-
auto begin =
419-
extensions::protobuf_internal::MapBegin(*reflection, *message_, *field_);
420-
const auto end =
421-
extensions::protobuf_internal::MapEnd(*reflection, *message_, *field_);
418+
auto begin = extensions::protobuf_internal::ConstMapBegin(*reflection,
419+
*message_, *field_);
420+
const auto end = extensions::protobuf_internal::ConstMapEnd(
421+
*reflection, *message_, *field_);
422422
for (; begin != end; ++begin) {
423423
Value scratch;
424424
(*key_accessor)(begin.GetKey(), message_, arena, &scratch);
@@ -446,10 +446,10 @@ absl::Status ParsedMapFieldValue::ForEach(
446446
CEL_ASSIGN_OR_RETURN(
447447
auto value_accessor,
448448
common_internal::MapFieldValueAccessorFor(value_field));
449-
auto begin = extensions::protobuf_internal::MapBegin(*reflection, *message_,
450-
*field_);
451-
const auto end =
452-
extensions::protobuf_internal::MapEnd(*reflection, *message_, *field_);
449+
auto begin = extensions::protobuf_internal::ConstMapBegin(
450+
*reflection, *message_, *field_);
451+
const auto end = extensions::protobuf_internal::ConstMapEnd(
452+
*reflection, *message_, *field_);
453453
Value key_scratch;
454454
Value value_scratch;
455455
for (; begin != end; ++begin) {
@@ -479,10 +479,10 @@ class ParsedMapFieldValueIterator final : public ValueIterator {
479479
value_field_(field->message_type()->map_value()),
480480
key_accessor_(key_accessor),
481481
value_accessor_(value_accessor),
482-
begin_(extensions::protobuf_internal::MapBegin(
482+
begin_(extensions::protobuf_internal::ConstMapBegin(
483483
*message_->GetReflection(), *message_, *field)),
484-
end_(extensions::protobuf_internal::MapEnd(*message_->GetReflection(),
485-
*message_, *field)) {}
484+
end_(extensions::protobuf_internal::ConstMapEnd(
485+
*message_->GetReflection(), *message_, *field)) {}
486486

487487
bool HasNext() override { return begin_ != end_; }
488488

@@ -545,8 +545,8 @@ class ParsedMapFieldValueIterator final : public ValueIterator {
545545
const google::protobuf::FieldDescriptor* absl_nonnull const value_field_;
546546
const absl_nonnull common_internal::MapFieldKeyAccessor key_accessor_;
547547
const absl_nonnull common_internal::MapFieldValueAccessor value_accessor_;
548-
google::protobuf::MapIterator begin_;
549-
const google::protobuf::MapIterator end_;
548+
proto2::ConstMapIterator begin_;
549+
const proto2::ConstMapIterator end_;
550550
};
551551

552552
} // namespace

extensions/protobuf/internal/map_reflection.cc

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,16 @@ class CelMapReflectionFriend final {
4242
return reflection.MapSize(message, &field);
4343
}
4444

45-
static google::protobuf::MapIterator MapBegin(const google::protobuf::Reflection& reflection,
46-
const google::protobuf::Message& message,
47-
const google::protobuf::FieldDescriptor& field) {
48-
return reflection.MapBegin(
49-
const_cast< // NOLINT(google3-runtime-proto-const-cast)
50-
google::protobuf::Message*>(&message),
51-
&field);
45+
static proto2::ConstMapIterator ConstMapBegin(
46+
const google::protobuf::Reflection& reflection, const google::protobuf::Message& message,
47+
const google::protobuf::FieldDescriptor& field) {
48+
return reflection.ConstMapBegin(&message, &field);
5249
}
5350

54-
static google::protobuf::MapIterator MapEnd(const google::protobuf::Reflection& reflection,
55-
const google::protobuf::Message& message,
56-
const google::protobuf::FieldDescriptor& field) {
57-
return reflection.MapEnd(
58-
const_cast< // NOLINT(google3-runtime-proto-const-cast)
59-
google::protobuf::Message*>(&message),
60-
&field);
51+
static proto2::ConstMapIterator ConstMapEnd(
52+
const google::protobuf::Reflection& reflection, const google::protobuf::Message& message,
53+
const google::protobuf::FieldDescriptor& field) {
54+
return reflection.ConstMapEnd(&message, &field);
6155
}
6256

6357
static bool InsertOrLookupMapValue(const google::protobuf::Reflection& reflection,
@@ -104,18 +98,18 @@ int MapSize(const google::protobuf::Reflection& reflection,
10498
field);
10599
}
106100

107-
google::protobuf::MapIterator MapBegin(const google::protobuf::Reflection& reflection,
108-
const google::protobuf::Message& message,
109-
const google::protobuf::FieldDescriptor& field) {
110-
return google::protobuf::expr::CelMapReflectionFriend::MapBegin(reflection, message,
111-
field);
101+
proto2::ConstMapIterator ConstMapBegin(const google::protobuf::Reflection& reflection,
102+
const google::protobuf::Message& message,
103+
const google::protobuf::FieldDescriptor& field) {
104+
return google::protobuf::expr::CelMapReflectionFriend::ConstMapBegin(reflection,
105+
message, field);
112106
}
113107

114-
google::protobuf::MapIterator MapEnd(const google::protobuf::Reflection& reflection,
115-
const google::protobuf::Message& message,
116-
const google::protobuf::FieldDescriptor& field) {
117-
return google::protobuf::expr::CelMapReflectionFriend::MapEnd(reflection, message,
118-
field);
108+
proto2::ConstMapIterator ConstMapEnd(const google::protobuf::Reflection& reflection,
109+
const google::protobuf::Message& message,
110+
const google::protobuf::FieldDescriptor& field) {
111+
return google::protobuf::expr::CelMapReflectionFriend::ConstMapEnd(reflection, message,
112+
field);
119113
}
120114

121115
bool InsertOrLookupMapValue(const google::protobuf::Reflection& reflection,

extensions/protobuf/internal/map_reflection.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ int MapSize(const google::protobuf::Reflection& reflection,
4242
const google::protobuf::Message& message,
4343
const google::protobuf::FieldDescriptor& field);
4444

45-
google::protobuf::MapIterator MapBegin(const google::protobuf::Reflection& reflection,
46-
const google::protobuf::Message& message,
47-
const google::protobuf::FieldDescriptor& field);
45+
proto2::ConstMapIterator ConstMapBegin(const google::protobuf::Reflection& reflection,
46+
const google::protobuf::Message& message,
47+
const google::protobuf::FieldDescriptor& field);
4848

49-
google::protobuf::MapIterator MapEnd(const google::protobuf::Reflection& reflection,
50-
const google::protobuf::Message& message,
51-
const google::protobuf::FieldDescriptor& field);
49+
proto2::ConstMapIterator ConstMapEnd(const google::protobuf::Reflection& reflection,
50+
const google::protobuf::Message& message,
51+
const google::protobuf::FieldDescriptor& field);
5252

5353
bool InsertOrLookupMapValue(const google::protobuf::Reflection& reflection,
5454
google::protobuf::Message* message,

internal/json.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -803,10 +803,10 @@ class MessageToJsonState {
803803
const auto* value_descriptor = field->message_type()->map_value();
804804
CEL_ASSIGN_OR_RETURN(const auto value_to_value,
805805
GetMapFieldValueToValue(value_descriptor));
806-
auto begin =
807-
extensions::protobuf_internal::MapBegin(*reflection, message, *field);
808-
const auto end =
809-
extensions::protobuf_internal::MapEnd(*reflection, message, *field);
806+
auto begin = extensions::protobuf_internal::ConstMapBegin(*reflection,
807+
message, *field);
808+
const auto end = extensions::protobuf_internal::ConstMapEnd(
809+
*reflection, message, *field);
810810
for (; begin != end; ++begin) {
811811
auto key = (*key_to_string)(begin.GetKey());
812812
CEL_RETURN_IF_ERROR((this->*value_to_value)(
@@ -1381,7 +1381,7 @@ class JsonMapIterator final {
13811381
using Generated =
13821382
typename google::protobuf::Map<std::string,
13831383
google::protobuf::Value>::const_iterator;
1384-
using Dynamic = google::protobuf::MapIterator;
1384+
using Dynamic = proto2::ConstMapIterator;
13851385
using Value = std::pair<well_known_types::StringValue,
13861386
const google::protobuf::MessageLite* absl_nonnull>;
13871387

internal/message_equality.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ namespace cel::internal {
5050

5151
namespace {
5252

53+
using ::cel::extensions::protobuf_internal::ConstMapBegin;
54+
using ::cel::extensions::protobuf_internal::ConstMapEnd;
5355
using ::cel::extensions::protobuf_internal::LookupMapValue;
54-
using ::cel::extensions::protobuf_internal::MapBegin;
55-
using ::cel::extensions::protobuf_internal::MapEnd;
5656
using ::cel::extensions::protobuf_internal::MapSize;
5757
using ::google::protobuf::Descriptor;
5858
using ::google::protobuf::DescriptorPool;
@@ -904,8 +904,8 @@ class MessageEqualsState final {
904904
MapSize(*rhs_reflection, rhs, *rhs_field)) {
905905
return false;
906906
}
907-
auto lhs_begin = MapBegin(*lhs_reflection, lhs, *lhs_field);
908-
const auto lhs_end = MapEnd(*lhs_reflection, lhs, *lhs_field);
907+
auto lhs_begin = ConstMapBegin(*lhs_reflection, lhs, *lhs_field);
908+
const auto lhs_end = ConstMapEnd(*lhs_reflection, lhs, *lhs_field);
909909
Unique<Message> lhs_unpacked;
910910
EquatableValue lhs_value;
911911
Unique<Message> rhs_unpacked;

internal/well_known_types.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,20 +1643,20 @@ int StructReflection::FieldsSize(const google::protobuf::Message& message) const
16431643
message, *fields_field_);
16441644
}
16451645

1646-
google::protobuf::MapIterator StructReflection::BeginFields(
1646+
proto2::ConstMapIterator StructReflection::BeginFields(
16471647
const google::protobuf::Message& message) const {
16481648
ABSL_DCHECK(IsInitialized());
16491649
ABSL_DCHECK_EQ(message.GetDescriptor(), descriptor_);
1650-
return cel::extensions::protobuf_internal::MapBegin(*message.GetReflection(),
1651-
message, *fields_field_);
1650+
return cel::extensions::protobuf_internal::ConstMapBegin(
1651+
*message.GetReflection(), message, *fields_field_);
16521652
}
16531653

1654-
google::protobuf::MapIterator StructReflection::EndFields(
1654+
proto2::ConstMapIterator StructReflection::EndFields(
16551655
const google::protobuf::Message& message) const {
16561656
ABSL_DCHECK(IsInitialized());
16571657
ABSL_DCHECK_EQ(message.GetDescriptor(), descriptor_);
1658-
return cel::extensions::protobuf_internal::MapEnd(*message.GetReflection(),
1659-
message, *fields_field_);
1658+
return cel::extensions::protobuf_internal::ConstMapEnd(
1659+
*message.GetReflection(), message, *fields_field_);
16601660
}
16611661

16621662
bool StructReflection::ContainsField(const google::protobuf::Message& message,

internal/well_known_types.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,9 @@ absl::StatusOr<AnyReflection> GetAnyReflection(
698698
const google::protobuf::Descriptor* absl_nonnull descriptor
699699
ABSL_ATTRIBUTE_LIFETIME_BOUND);
700700

701-
AnyReflection GetAnyReflectionOrDie(const google::protobuf::Descriptor* absl_nonnull
702-
descriptor ABSL_ATTRIBUTE_LIFETIME_BOUND);
701+
AnyReflection GetAnyReflectionOrDie(
702+
const google::protobuf::Descriptor* absl_nonnull descriptor
703+
ABSL_ATTRIBUTE_LIFETIME_BOUND);
703704

704705
class DurationReflection final {
705706
public:
@@ -1193,10 +1194,10 @@ class StructReflection final {
11931194

11941195
int FieldsSize(const google::protobuf::Message& message) const;
11951196

1196-
google::protobuf::MapIterator BeginFields(
1197+
proto2::ConstMapIterator BeginFields(
11971198
const google::protobuf::Message& message ABSL_ATTRIBUTE_LIFETIME_BOUND) const;
11981199

1199-
google::protobuf::MapIterator EndFields(
1200+
proto2::ConstMapIterator EndFields(
12001201
const google::protobuf::Message& message ABSL_ATTRIBUTE_LIFETIME_BOUND) const;
12011202

12021203
bool ContainsField(const google::protobuf::Message& message,

0 commit comments

Comments
 (0)