From 885b612f74f133678bf82808c589331e4c59dad9 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Sat, 28 Feb 2015 14:51:22 -0800 Subject: Down integrate from Google internal branch for C++ and Java. - Maps for C++ lite - C++ Arena optimizations. - Java Lite runtime code size optimization. Change-Id: I7537a4357c1cb385d23f9e8aa7ffdfeefe079f13 --- .../protobuf/generated_message_reflection.cc | 41 ++++++++++++---------- 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'src/google/protobuf/generated_message_reflection.cc') diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index 34826801..412c48a1 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -995,6 +995,7 @@ void GeneratedMessageReflection::ListFields( // Optimization: The default instance never has any fields set. if (&message == default_instance_) return; + output->reserve(descriptor_->field_count()); for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* field = descriptor_->field(i); if (field->is_repeated()) { @@ -1018,7 +1019,7 @@ void GeneratedMessageReflection::ListFields( } // ListFields() must sort output by field number. - sort(output->begin(), output->end(), FieldNumberSorter()); + std::sort(output->begin(), output->end(), FieldNumberSorter()); } // ------------------------------------------------------------------- @@ -1434,6 +1435,8 @@ const Message& GeneratedMessageReflection::GetMessage( Message* GeneratedMessageReflection::MutableMessage( Message* message, const FieldDescriptor* field, MessageFactory* factory) const { + USAGE_CHECK_ALL(MutableMessage, SINGULAR, MESSAGE); + if (factory == NULL) factory = message_factory_; if (field->is_extension()) { @@ -1972,26 +1975,28 @@ inline void GeneratedMessageReflection::ClearOneof( uint32 oneof_case = GetOneofCase(*message, oneof_descriptor); if (oneof_case > 0) { const FieldDescriptor* field = descriptor_->FindFieldByNumber(oneof_case); - switch (field->cpp_type()) { - case FieldDescriptor::CPPTYPE_STRING: { - switch (field->options().ctype()) { - default: // TODO(kenton): Support other string reps. - case FieldOptions::STRING: { - const string* default_ptr = - &DefaultRaw(field).Get(NULL); - MutableField(message, field)-> - Destroy(default_ptr, GetArena(message)); - break; + if (GetArena(message) == NULL) { + switch (field->cpp_type()) { + case FieldDescriptor::CPPTYPE_STRING: { + switch (field->options().ctype()) { + default: // TODO(kenton): Support other string reps. + case FieldOptions::STRING: { + const string* default_ptr = + &DefaultRaw(field).Get(NULL); + MutableField(message, field)-> + Destroy(default_ptr, GetArena(message)); + break; + } } + break; } - break; - } - case FieldDescriptor::CPPTYPE_MESSAGE: - delete *MutableRaw(message, field); - break; - default: - break; + case FieldDescriptor::CPPTYPE_MESSAGE: + delete *MutableRaw(message, field); + break; + default: + break; + } } *MutableOneofCase(message, oneof_descriptor) = 0; -- cgit v1.2.3