Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/google/protobuf/io/tokenizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,9 @@ void Tokenizer::ParseStringAppend(const std::string& text,
// downsize the output.
const size_t new_len = text_size + output->size();
if (new_len > output->capacity()) {
output->reserve(new_len);
// Make sure to use amortized growth if we already have a value.
output->reserve(
output->empty() ? new_len : std::max(new_len, output->capacity() * 2));
}

// Loop through the string copying characters to "output" and
Expand Down
3 changes: 3 additions & 0 deletions src/google/protobuf/text_format_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ using ::absl_testing::StatusIs;
using ::google::protobuf::internal::UnsetFieldsMetadataTextFormatTestUtil;
using ::testing::_;
using ::testing::AllOf;
using ::testing::Gt;
using ::testing::HasSubstr;
using ::testing::Lt;
using ::testing::UnorderedElementsAre;

absl::string_view GetSubstring(absl::string_view input,
Expand Down Expand Up @@ -1391,6 +1393,7 @@ TEST_F(TextFormatTest, ParseConcatenatedString) {
EXPECT_EQ("foobar", proto_.optional_string());
}


TEST_F(TextFormatTest, ParseFloatWithSuffix) {
// Test that we can parse a floating-point value with 'f' appended to the
// end. This is needed for backwards-compatibility with proto1.
Expand Down
Loading