@@ -107,9 +107,13 @@ PROTOBUF_EXPORT void LogIndexOutOfBounds(int index, int size);
107107PROTOBUF_PRESERVE_ALL PROTOBUF_EXPORT void LogIndexOutOfBoundsAndAbort (
108108 int index, int size);
109109PROTOBUF_EXPORT inline void RuntimeAssertInBounds (int index, int size) {
110- if (ABSL_PREDICT_FALSE (index < 0 || index >= size)) {
111- LogIndexOutOfBoundsAndAbort (index, size);
110+ if constexpr (GetBoundsCheckMode () == BoundsCheckMode::kAbort ) {
111+ if (ABSL_PREDICT_FALSE (index < 0 || index >= size)) {
112+ LogIndexOutOfBoundsAndAbort (index, size);
113+ }
112114 }
115+ ABSL_DCHECK_GE (index, 0 );
116+ ABSL_DCHECK_LT (index, size);
113117}
114118
115119// Defined further below.
@@ -196,12 +200,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase {
196200
197201 template <typename TypeHandler>
198202 Value<TypeHandler>* Mutable (int index) {
199- if constexpr (GetBoundsCheckMode () == BoundsCheckMode::kAbort ) {
200203 RuntimeAssertInBounds (index, current_size_);
201- } else {
202- ABSL_DCHECK_GE (index, 0 );
203- ABSL_DCHECK_LT (index, current_size_);
204- }
205204 return cast<TypeHandler>(element_at (index));
206205 }
207206
@@ -271,14 +270,10 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase {
271270 return TypeHandler::default_instance ();
272271 }
273272 }
274- } else if constexpr (GetBoundsCheckMode () == BoundsCheckMode::kAbort ) {
275- // We refactor this to a separate function instead of inlining it so we
276- // can measure the performance impact more easily.
277- RuntimeAssertInBounds (index, current_size_);
278- } else {
279- ABSL_DCHECK_GE (index, 0 );
280- ABSL_DCHECK_LT (index, current_size_);
281273 }
274+ // We refactor this to a separate function instead of inlining it so we
275+ // can measure the performance impact more easily.
276+ RuntimeAssertInBounds (index, current_size_);
282277 return *cast<TypeHandler>(element_at (index));
283278 }
284279
0 commit comments