Minor refactor to avoid lifetime bound warnings on some callers.

PiperOrigin-RevId: 723052963
pull/20206/head
Protobuf Team Bot 3 weeks ago committed by Copybara-Service
parent 9bb6daaead
commit 6c10485b9b
  1. 16
      src/google/protobuf/generated_message_reflection.cc
  2. 5
      src/google/protobuf/message.h

@ -1974,11 +1974,9 @@ absl::Cord Reflection::GetCord(const Message& message,
}
}
absl::string_view Reflection::GetStringView(const Message& message,
absl::string_view Reflection::GetStringViewImpl(const Message& message,
const FieldDescriptor* field,
ScratchSpace& scratch) const {
USAGE_CHECK_ALL(GetStringView, SINGULAR, STRING);
ScratchSpace* scratch) const {
if (field->is_extension()) {
return GetExtensionSet(message).GetString(
field->number(), internal::DefaultValueStringAsString(field));
@ -1992,7 +1990,8 @@ absl::string_view Reflection::GetStringView(const Message& message,
const auto& cord = schema_.InRealOneof(field)
? *GetField<absl::Cord*>(message, field)
: GetField<absl::Cord>(message, field);
return scratch.CopyFromCord(cord);
ABSL_DCHECK(scratch);
return scratch->CopyFromCord(cord);
}
default:
auto str = GetField<ArenaStringPtr>(message, field);
@ -2000,6 +1999,13 @@ absl::string_view Reflection::GetStringView(const Message& message,
}
}
absl::string_view Reflection::GetStringView(const Message& message,
const FieldDescriptor* field,
ScratchSpace& scratch) const {
USAGE_CHECK_ALL(GetStringView, SINGULAR, STRING);
return GetStringViewImpl(message, field, &scratch);
}
void Reflection::SetString(Message* message, const FieldDescriptor* field,
std::string value) const {

@ -987,6 +987,11 @@ class PROTOBUF_EXPORT Reflection final {
RepeatedPtrField<T>* MutableRepeatedPtrFieldInternal(
Message* message, const FieldDescriptor* field) const;
// REQUIRES: If the field is Cord, then `scratch != nullptr`.
absl::string_view GetStringViewImpl(const Message& message,
const FieldDescriptor* field,
ScratchSpace* scratch) const;
// Obtain a pointer to a Repeated Field Structure and do some type checking:
// on field->cpp_type(),
// on field->field_option().ctype() (if ctype >= 0)

Loading…
Cancel
Save