diff options
author | kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2008-11-21 00:06:27 +0000 |
---|---|---|
committer | kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2008-11-21 00:06:27 +0000 |
commit | 26bd9eee6ee6d116e1cc0dedeb660cd69d7aac45 (patch) | |
tree | d35cca89e0da44f136090a554ff9abc93a794fa8 /src/google/protobuf/io | |
parent | a2a32c20434807e9966e3f48375f9419134d1b55 (diff) | |
download | protobuf-javalite-26bd9eee6ee6d116e1cc0dedeb660cd69d7aac45.tar.gz |
Integrate changes from internal code.
protoc
* Enum values may now have custom options, using syntax similar to field
options.
* Fixed bug where .proto files which use custom options but don't actually
define them (i.e. they import another .proto file defining the options)
had to explicitly import descriptor.proto.
* Adjacent string literals in .proto files will now be concatenated, like in
C.
C++
* Generated message classes now have a Swap() method which efficiently swaps
the contents of two objects.
* All message classes now have a SpaceUsed() method which returns an estimate
of the number of bytes of allocated memory currently owned by the object.
This is particularly useful when you are reusing a single message object
to improve performance but want to make sure it doesn't bloat up too large.
* New method Message::SerializeAsString() returns a string containing the
serialized data. May be more convenient than calling
SerializeToString(string*).
* In debug mode, log error messages when string-type fields are found to
contain bytes that are not valid UTF-8.
* Fixed bug where a message with multiple extension ranges couldn't parse
extensions.
* Fixed bug where MergeFrom(const Message&) didn't do anything if invoked on
a message that contained no fields (but possibly contained extensions).
* Fixed ShortDebugString() to not be O(n^2). Durr.
* Fixed crash in TextFormat parsing if the first token in the input caused a
tokenization error.
Java
* New overload of mergeFrom() which parses a slice of a byte array instead
of the whole thing.
* New method ByteString.asReadOnlyByteBuffer() does what it sounds like.
* Improved performance of isInitialized() when optimizing for code size.
Python
* Corrected ListFields() signature in Message base class to match what
subclasses actually implement.
* Some minor refactoring.
Diffstat (limited to 'src/google/protobuf/io')
-rw-r--r-- | src/google/protobuf/io/tokenizer.cc | 10 | ||||
-rw-r--r-- | src/google/protobuf/io/tokenizer.h | 8 | ||||
-rw-r--r-- | src/google/protobuf/io/tokenizer_unittest.cc | 9 | ||||
-rw-r--r-- | src/google/protobuf/io/zero_copy_stream_unittest.cc | 4 |
4 files changed, 24 insertions, 7 deletions
diff --git a/src/google/protobuf/io/tokenizer.cc b/src/google/protobuf/io/tokenizer.cc index 8c12fac5..4823912a 100644 --- a/src/google/protobuf/io/tokenizer.cc +++ b/src/google/protobuf/io/tokenizer.cc @@ -623,19 +623,17 @@ double Tokenizer::ParseFloat(const string& text) { return result; } -void Tokenizer::ParseString(const string& text, string* output) { - output->clear(); - +void Tokenizer::ParseStringAppend(const string& text, string* output) { // Reminder: text[0] is always the quote character. (If text is // empty, it's invalid, so we'll just return.) if (text.empty()) { GOOGLE_LOG(DFATAL) - << " ParseString::ParseString() passed text that could not have been" - " tokenized as a string: " << CEscape(text); + << " Tokenizer::ParseStringAppend() passed text that could not" + " have been tokenized as a string: " << CEscape(text); return; } - output->reserve(text.size()); + output->reserve(output->size() + text.size()); // Loop through the string copying characters to "output" and // interpreting escape sequences. Note that any invalid escape diff --git a/src/google/protobuf/io/tokenizer.h b/src/google/protobuf/io/tokenizer.h index 048a588f..98386e0b 100644 --- a/src/google/protobuf/io/tokenizer.h +++ b/src/google/protobuf/io/tokenizer.h @@ -139,6 +139,9 @@ class LIBPROTOBUF_EXPORT Tokenizer { // result is undefined (possibly an assert failure). static void ParseString(const string& text, string* output); + // Identical to ParseString, but appends to output. + static void ParseStringAppend(const string& text, string* output); + // Parses a TYPE_INTEGER token. Returns false if the result would be // greater than max_value. Otherwise, returns true and sets *output to the // result. If the text is not from a Token of type TYPE_INTEGER originally @@ -283,6 +286,11 @@ inline const Tokenizer::Token& Tokenizer::current() { return current_; } +inline void Tokenizer::ParseString(const string& text, string* output) { + output->clear(); + ParseStringAppend(text, output); +} + } // namespace io } // namespace protobuf diff --git a/src/google/protobuf/io/tokenizer_unittest.cc b/src/google/protobuf/io/tokenizer_unittest.cc index c0f5aefd..dd7ed5c8 100644 --- a/src/google/protobuf/io/tokenizer_unittest.cc +++ b/src/google/protobuf/io/tokenizer_unittest.cc @@ -584,6 +584,15 @@ TEST_F(TokenizerTest, ParseString) { #endif // GTEST_HAS_DEATH_TEST } +TEST_F(TokenizerTest, ParseStringAppend) { + // Check that ParseString and ParseStringAppend differ. + string output("stuff+"); + Tokenizer::ParseStringAppend("'hello'", &output); + EXPECT_EQ("stuff+hello", output); + Tokenizer::ParseString("'hello'", &output); + EXPECT_EQ("hello", output); +} + // ------------------------------------------------------------------- // Each case parses some input text, ignoring the tokens produced, and diff --git a/src/google/protobuf/io/zero_copy_stream_unittest.cc b/src/google/protobuf/io/zero_copy_stream_unittest.cc index ec92127d..2ee9e6c4 100644 --- a/src/google/protobuf/io/zero_copy_stream_unittest.cc +++ b/src/google/protobuf/io/zero_copy_stream_unittest.cc @@ -156,7 +156,9 @@ int IoTest::ReadFromInput(ZeroCopyInputStream* input, void* data, int size) { if (out_size <= in_size) { memcpy(out, in, out_size); - input->BackUp(in_size - out_size); + if (in_size > out_size) { + input->BackUp(in_size - out_size); + } return size; // Copied all of it. } |