From 26bd9eee6ee6d116e1cc0dedeb660cd69d7aac45 Mon Sep 17 00:00:00 2001 From: "kenton@google.com" Date: Fri, 21 Nov 2008 00:06:27 +0000 Subject: 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. --- src/google/protobuf/unknown_field_set.cc | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/google/protobuf/unknown_field_set.cc') diff --git a/src/google/protobuf/unknown_field_set.cc b/src/google/protobuf/unknown_field_set.cc index b170d41d..6a9be5a4 100644 --- a/src/google/protobuf/unknown_field_set.cc +++ b/src/google/protobuf/unknown_field_set.cc @@ -130,6 +130,30 @@ UnknownField* UnknownFieldSet::AddField(int number) { return field; } +int UnknownFieldSet::SpaceUsedExcludingSelf() const { + int total_size = 0; + if (internal_ != NULL) { + total_size += sizeof(*internal_); + total_size += internal_->active_fields_.capacity() * + sizeof(Internal::FieldVector::value_type); + total_size += internal_->fields_.size() * + sizeof(Internal::FieldMap::value_type); + + // Account for the UnknownField objects themselves. + for (Internal::FieldMap::const_iterator it = internal_->fields_.begin(), + end = internal_->fields_.end(); + it != end; + ++it) { + total_size += it->second->SpaceUsed(); + } + } + return total_size; +} + +int UnknownFieldSet::SpaceUsed() const { + return sizeof(*this) + SpaceUsedExcludingSelf(); +} + UnknownField::UnknownField(int number) : number_(number), index_(-1) { @@ -154,5 +178,15 @@ void UnknownField::MergeFrom(const UnknownField& other) { group_ .MergeFrom(other.group_ ); } +int UnknownField::SpaceUsed() const { + int total_size = sizeof(*this); + total_size += varint_.SpaceUsedExcludingSelf(); + total_size += fixed32_.SpaceUsedExcludingSelf(); + total_size += fixed64_.SpaceUsedExcludingSelf(); + total_size += length_delimited_.SpaceUsedExcludingSelf(); + total_size += group_.SpaceUsedExcludingSelf(); + return total_size; +} + } // namespace protobuf } // namespace google -- cgit v1.2.3