Skip to content

Commit

Permalink
TextFormat::ParseFieldValueFromString now takes absl::string_view
Browse files Browse the repository at this point in the history
… as `input` instead of `const std::string &`

`TextFormat::ParseFieldValueFromString` would take `const std::string &` as the input, but it's a read-only string and immediately passed to `ArrayInputStream`. This CL will change it to `absl::string_view`.

PiperOrigin-RevId: 540609068
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Jun 15, 2023
1 parent 0a45abe commit 5411fc6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/google/protobuf/text_format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,7 @@ bool TextFormat::Parser::MergeUsingImpl(io::ZeroCopyInputStream* /* input */,
return true;
}

bool TextFormat::Parser::ParseFieldValueFromString(const std::string& input,
bool TextFormat::Parser::ParseFieldValueFromString(absl::string_view input,
const FieldDescriptor* field,
Message* output) {
io::ArrayInputStream input_stream(input.data(), input.size());
Expand Down Expand Up @@ -2757,7 +2757,7 @@ void TextFormat::Printer::PrintFieldValue(const Message& message,
}

/* static */ bool TextFormat::ParseFieldValueFromString(
const std::string& input, const FieldDescriptor* field, Message* message) {
absl::string_view input, const FieldDescriptor* field, Message* message) {
return Parser().ParseFieldValueFromString(input, field, message);
}

Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/text_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ class PROTOBUF_EXPORT TextFormat {
// Parse the given text as a single field value and store it into the
// given field of the given message. If the field is a repeated field,
// the new value will be added to the end
static bool ParseFieldValueFromString(const std::string& input,
static bool ParseFieldValueFromString(absl::string_view input,
const FieldDescriptor* field,
Message* message);

Expand Down Expand Up @@ -707,7 +707,7 @@ class PROTOBUF_EXPORT TextFormat {
}

// Like TextFormat::ParseFieldValueFromString
bool ParseFieldValueFromString(const std::string& input,
bool ParseFieldValueFromString(absl::string_view input,
const FieldDescriptor* field,
Message* output);

Expand Down

0 comments on commit 5411fc6

Please sign in to comment.