Skip to content

Commit

Permalink
Minor refactor to avoid lifetime bound warnings on some callers.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 725319090
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Feb 10, 2025
1 parent 482f1ca commit e3b1210
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/google/protobuf/generated_message_reflection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2149,20 +2149,18 @@ const std::string& Reflection::GetRepeatedStringReference(
}

// See GetStringView(), above.
absl::string_view Reflection::GetRepeatedStringView(
absl::string_view Reflection::GetRepeatedStringViewImpl(
const Message& message, const FieldDescriptor* field, int index,
ScratchSpace& scratch) const {
(void)scratch;
USAGE_CHECK_ALL(GetRepeatedStringView, REPEATED, STRING);

ScratchSpace* scratch) const {
if (field->is_extension()) {
return GetExtensionSet(message).GetRepeatedString(field->number(), index);
}

switch (field->cpp_string_type()) {
case FieldDescriptor::CppStringType::kCord: {
auto& cord = GetRepeatedField<absl::Cord>(message, field, index);
return scratch.CopyFromCord(cord);
ABSL_DCHECK(scratch);
return scratch->CopyFromCord(cord);
}
case FieldDescriptor::CppStringType::kView:
case FieldDescriptor::CppStringType::kString:
Expand All @@ -2171,6 +2169,13 @@ absl::string_view Reflection::GetRepeatedStringView(
internal::Unreachable();
}

absl::string_view Reflection::GetRepeatedStringView(
const Message& message, const FieldDescriptor* field, int index,
ScratchSpace& scratch) const {
USAGE_CHECK_ALL(GetRepeatedStringView, REPEATED, STRING);
return GetRepeatedStringViewImpl(message, field, index, &scratch);
}


void Reflection::SetRepeatedString(Message* message,
const FieldDescriptor* field, int index,
Expand Down
4 changes: 4 additions & 0 deletions src/google/protobuf/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,10 @@ class PROTOBUF_EXPORT Reflection final {
absl::string_view GetStringViewImpl(const Message& message,
const FieldDescriptor* field,
ScratchSpace* scratch) const;
absl::string_view GetRepeatedStringViewImpl(const Message& message,
const FieldDescriptor* field,
int index,
ScratchSpace* scratch) const;

// Obtain a pointer to a Repeated Field Structure and do some type checking:
// on field->cpp_type(),
Expand Down

0 comments on commit e3b1210

Please sign in to comment.