Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: third_party/protobuf/src/google/protobuf/extension_set.cc

Issue 21208003: Update protobuf to r428, part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // http://code.google.com/p/protobuf/ 3 // http://code.google.com/p/protobuf/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 ExtensionRegistry* registry_ = NULL; 64 ExtensionRegistry* registry_ = NULL;
65 GOOGLE_PROTOBUF_DECLARE_ONCE(registry_init_); 65 GOOGLE_PROTOBUF_DECLARE_ONCE(registry_init_);
66 66
67 void DeleteRegistry() { 67 void DeleteRegistry() {
68 delete registry_; 68 delete registry_;
69 registry_ = NULL; 69 registry_ = NULL;
70 } 70 }
71 71
72 void InitRegistry() { 72 void InitRegistry() {
73 registry_ = new ExtensionRegistry; 73 registry_ = new ExtensionRegistry;
74 internal::OnShutdown(&DeleteRegistry); 74 OnShutdown(&DeleteRegistry);
75 } 75 }
76 76
77 // This function is only called at startup, so there is no need for thread- 77 // This function is only called at startup, so there is no need for thread-
78 // safety. 78 // safety.
79 void Register(const MessageLite* containing_type, 79 void Register(const MessageLite* containing_type,
80 int number, ExtensionInfo info) { 80 int number, ExtensionInfo info) {
81 ::google::protobuf::GoogleOnceInit(&registry_init_, &InitRegistry); 81 ::google::protobuf::GoogleOnceInit(&registry_init_, &InitRegistry);
82 82
83 if (!InsertIfNotPresent(registry_, make_pair(containing_type, number), 83 if (!InsertIfNotPresent(registry_, make_pair(containing_type, number),
84 info)) { 84 info)) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // const DescriptorPool* pool, 173 // const DescriptorPool* pool,
174 // vector<const FieldDescriptor*>* output) const 174 // vector<const FieldDescriptor*>* output) const
175 175
176 bool ExtensionSet::Has(int number) const { 176 bool ExtensionSet::Has(int number) const {
177 map<int, Extension>::const_iterator iter = extensions_.find(number); 177 map<int, Extension>::const_iterator iter = extensions_.find(number);
178 if (iter == extensions_.end()) return false; 178 if (iter == extensions_.end()) return false;
179 GOOGLE_DCHECK(!iter->second.is_repeated); 179 GOOGLE_DCHECK(!iter->second.is_repeated);
180 return !iter->second.is_cleared; 180 return !iter->second.is_cleared;
181 } 181 }
182 182
183 int ExtensionSet::NumExtensions() const {
184 int result = 0;
185 for (map<int, Extension>::const_iterator iter = extensions_.begin();
186 iter != extensions_.end(); ++iter) {
187 if (!iter->second.is_cleared) {
188 ++result;
189 }
190 }
191 return result;
192 }
193
183 int ExtensionSet::ExtensionSize(int number) const { 194 int ExtensionSet::ExtensionSize(int number) const {
184 map<int, Extension>::const_iterator iter = extensions_.find(number); 195 map<int, Extension>::const_iterator iter = extensions_.find(number);
185 if (iter == extensions_.end()) return false; 196 if (iter == extensions_.end()) return false;
186 return iter->second.GetSize(); 197 return iter->second.GetSize();
187 } 198 }
188 199
189 FieldType ExtensionSet::ExtensionType(int number) const { 200 FieldType ExtensionSet::ExtensionType(int number) const {
190 map<int, Extension>::const_iterator iter = extensions_.find(number); 201 map<int, Extension>::const_iterator iter = extensions_.find(number);
191 if (iter == extensions_.end()) { 202 if (iter == extensions_.end()) {
192 GOOGLE_LOG(DFATAL) << "Don't lookup extension types if they aren't present ( 1). "; 203 GOOGLE_LOG(DFATAL) << "Don't lookup extension types if they aren't present ( 1). ";
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 PRIMITIVE_ACCESSORS( INT32, int32, Int32) 297 PRIMITIVE_ACCESSORS( INT32, int32, Int32)
287 PRIMITIVE_ACCESSORS( INT64, int64, Int64) 298 PRIMITIVE_ACCESSORS( INT64, int64, Int64)
288 PRIMITIVE_ACCESSORS(UINT32, uint32, UInt32) 299 PRIMITIVE_ACCESSORS(UINT32, uint32, UInt32)
289 PRIMITIVE_ACCESSORS(UINT64, uint64, UInt64) 300 PRIMITIVE_ACCESSORS(UINT64, uint64, UInt64)
290 PRIMITIVE_ACCESSORS( FLOAT, float, Float) 301 PRIMITIVE_ACCESSORS( FLOAT, float, Float)
291 PRIMITIVE_ACCESSORS(DOUBLE, double, Double) 302 PRIMITIVE_ACCESSORS(DOUBLE, double, Double)
292 PRIMITIVE_ACCESSORS( BOOL, bool, Bool) 303 PRIMITIVE_ACCESSORS( BOOL, bool, Bool)
293 304
294 #undef PRIMITIVE_ACCESSORS 305 #undef PRIMITIVE_ACCESSORS
295 306
307 void* ExtensionSet::MutableRawRepeatedField(int number) {
308 // We assume that all the RepeatedField<>* pointers have the same
309 // size and alignment within the anonymous union in Extension.
310 map<int, Extension>::const_iterator iter = extensions_.find(number);
311 GOOGLE_CHECK(iter != extensions_.end()) << "no extension numbered " << number;
312 return iter->second.repeated_int32_value;
313 }
314
296 // ------------------------------------------------------------------- 315 // -------------------------------------------------------------------
297 // Enums 316 // Enums
298 317
299 int ExtensionSet::GetEnum(int number, int default_value) const { 318 int ExtensionSet::GetEnum(int number, int default_value) const {
300 map<int, Extension>::const_iterator iter = extensions_.find(number); 319 map<int, Extension>::const_iterator iter = extensions_.find(number);
301 if (iter == extensions_.end() || iter->second.is_cleared) { 320 if (iter == extensions_.end() || iter->second.is_cleared) {
302 // Not present. Return the default value. 321 // Not present. Return the default value.
303 return default_value; 322 return default_value;
304 } else { 323 } else {
305 GOOGLE_DCHECK_TYPE(iter->second, OPTIONAL, ENUM); 324 GOOGLE_DCHECK_TYPE(iter->second, OPTIONAL, ENUM);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 // Messages 434 // Messages
416 435
417 const MessageLite& ExtensionSet::GetMessage( 436 const MessageLite& ExtensionSet::GetMessage(
418 int number, const MessageLite& default_value) const { 437 int number, const MessageLite& default_value) const {
419 map<int, Extension>::const_iterator iter = extensions_.find(number); 438 map<int, Extension>::const_iterator iter = extensions_.find(number);
420 if (iter == extensions_.end()) { 439 if (iter == extensions_.end()) {
421 // Not present. Return the default value. 440 // Not present. Return the default value.
422 return default_value; 441 return default_value;
423 } else { 442 } else {
424 GOOGLE_DCHECK_TYPE(iter->second, OPTIONAL, MESSAGE); 443 GOOGLE_DCHECK_TYPE(iter->second, OPTIONAL, MESSAGE);
425 return *iter->second.message_value; 444 if (iter->second.is_lazy) {
445 return iter->second.lazymessage_value->GetMessage(default_value);
446 } else {
447 return *iter->second.message_value;
448 }
426 } 449 }
427 } 450 }
428 451
429 // Defined in extension_set_heavy.cc. 452 // Defined in extension_set_heavy.cc.
430 // const MessageLite& ExtensionSet::GetMessage(int number, 453 // const MessageLite& ExtensionSet::GetMessage(int number,
431 // const Descriptor* message_type, 454 // const Descriptor* message_type,
432 // MessageFactory* factory) const 455 // MessageFactory* factory) const
433 456
434 MessageLite* ExtensionSet::MutableMessage(int number, FieldType type, 457 MessageLite* ExtensionSet::MutableMessage(int number, FieldType type,
435 const MessageLite& prototype, 458 const MessageLite& prototype,
436 const FieldDescriptor* descriptor) { 459 const FieldDescriptor* descriptor) {
437 Extension* extension; 460 Extension* extension;
438 if (MaybeNewExtension(number, descriptor, &extension)) { 461 if (MaybeNewExtension(number, descriptor, &extension)) {
439 extension->type = type; 462 extension->type = type;
440 GOOGLE_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_MESSAGE) ; 463 GOOGLE_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_MESSAGE) ;
441 extension->is_repeated = false; 464 extension->is_repeated = false;
465 extension->is_lazy = false;
442 extension->message_value = prototype.New(); 466 extension->message_value = prototype.New();
467 extension->is_cleared = false;
468 return extension->message_value;
443 } else { 469 } else {
444 GOOGLE_DCHECK_TYPE(*extension, OPTIONAL, MESSAGE); 470 GOOGLE_DCHECK_TYPE(*extension, OPTIONAL, MESSAGE);
471 extension->is_cleared = false;
472 if (extension->is_lazy) {
473 return extension->lazymessage_value->MutableMessage(prototype);
474 } else {
475 return extension->message_value;
476 }
445 } 477 }
446 extension->is_cleared = false;
447 return extension->message_value;
448 } 478 }
449 479
450 // Defined in extension_set_heavy.cc. 480 // Defined in extension_set_heavy.cc.
451 // MessageLite* ExtensionSet::MutableMessage(int number, FieldType type, 481 // MessageLite* ExtensionSet::MutableMessage(int number, FieldType type,
452 // const Descriptor* message_type, 482 // const Descriptor* message_type,
453 // MessageFactory* factory) 483 // MessageFactory* factory)
454 484
485 void ExtensionSet::SetAllocatedMessage(int number, FieldType type,
486 const FieldDescriptor* descriptor,
487 MessageLite* message) {
488 if (message == NULL) {
489 ClearExtension(number);
490 return;
491 }
492 Extension* extension;
493 if (MaybeNewExtension(number, descriptor, &extension)) {
494 extension->type = type;
495 GOOGLE_DCHECK_EQ(cpp_type(extension->type), WireFormatLite::CPPTYPE_MESSAGE) ;
496 extension->is_repeated = false;
497 extension->is_lazy = false;
498 extension->message_value = message;
499 } else {
500 GOOGLE_DCHECK_TYPE(*extension, OPTIONAL, MESSAGE);
501 if (extension->is_lazy) {
502 extension->lazymessage_value->SetAllocatedMessage(message);
503 } else {
504 delete extension->message_value;
505 extension->message_value = message;
506 }
507 }
508 extension->is_cleared = false;
509 }
510
511 MessageLite* ExtensionSet::ReleaseMessage(int number,
512 const MessageLite& prototype) {
513 map<int, Extension>::iterator iter = extensions_.find(number);
514 if (iter == extensions_.end()) {
515 // Not present. Return NULL.
516 return NULL;
517 } else {
518 GOOGLE_DCHECK_TYPE(iter->second, OPTIONAL, MESSAGE);
519 MessageLite* ret = NULL;
520 if (iter->second.is_lazy) {
521 ret = iter->second.lazymessage_value->ReleaseMessage(prototype);
522 delete iter->second.lazymessage_value;
523 } else {
524 ret = iter->second.message_value;
525 }
526 extensions_.erase(number);
527 return ret;
528 }
529 }
530
531 // Defined in extension_set_heavy.cc.
532 // MessageLite* ExtensionSet::ReleaseMessage(const FieldDescriptor* descriptor,
533 // MessageFactory* factory);
534
455 const MessageLite& ExtensionSet::GetRepeatedMessage( 535 const MessageLite& ExtensionSet::GetRepeatedMessage(
456 int number, int index) const { 536 int number, int index) const {
457 map<int, Extension>::const_iterator iter = extensions_.find(number); 537 map<int, Extension>::const_iterator iter = extensions_.find(number);
458 GOOGLE_CHECK(iter != extensions_.end()) << "Index out-of-bounds (field is empt y)."; 538 GOOGLE_CHECK(iter != extensions_.end()) << "Index out-of-bounds (field is empt y).";
459 GOOGLE_DCHECK_TYPE(iter->second, REPEATED, MESSAGE); 539 GOOGLE_DCHECK_TYPE(iter->second, REPEATED, MESSAGE);
460 return iter->second.repeated_message_value->Get(index); 540 return iter->second.repeated_message_value->Get(index);
461 } 541 }
462 542
463 MessageLite* ExtensionSet::MutableRepeatedMessage(int number, int index) { 543 MessageLite* ExtensionSet::MutableRepeatedMessage(int number, int index) {
464 map<int, Extension>::iterator iter = extensions_.find(number); 544 map<int, Extension>::iterator iter = extensions_.find(number);
(...skipping 12 matching lines...) Expand all
477 extension->is_repeated = true; 557 extension->is_repeated = true;
478 extension->repeated_message_value = 558 extension->repeated_message_value =
479 new RepeatedPtrField<MessageLite>(); 559 new RepeatedPtrField<MessageLite>();
480 } else { 560 } else {
481 GOOGLE_DCHECK_TYPE(*extension, REPEATED, MESSAGE); 561 GOOGLE_DCHECK_TYPE(*extension, REPEATED, MESSAGE);
482 } 562 }
483 563
484 // RepeatedPtrField<MessageLite> does not know how to Add() since it cannot 564 // RepeatedPtrField<MessageLite> does not know how to Add() since it cannot
485 // allocate an abstract object, so we have to be tricky. 565 // allocate an abstract object, so we have to be tricky.
486 MessageLite* result = extension->repeated_message_value 566 MessageLite* result = extension->repeated_message_value
487 ->AddFromCleared<internal::GenericTypeHandler<MessageLite> >(); 567 ->AddFromCleared<GenericTypeHandler<MessageLite> >();
488 if (result == NULL) { 568 if (result == NULL) {
489 result = prototype.New(); 569 result = prototype.New();
490 extension->repeated_message_value->AddAllocated(result); 570 extension->repeated_message_value->AddAllocated(result);
491 } 571 }
492 return result; 572 return result;
493 } 573 }
494 574
495 // Defined in extension_set_heavy.cc. 575 // Defined in extension_set_heavy.cc.
496 // MessageLite* ExtensionSet::AddMessage(int number, FieldType type, 576 // MessageLite* ExtensionSet::AddMessage(int number, FieldType type,
497 // const Descriptor* message_type, 577 // const Descriptor* message_type,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 break; 613 break;
534 case WireFormatLite::CPPTYPE_STRING: 614 case WireFormatLite::CPPTYPE_STRING:
535 extension->repeated_string_value->RemoveLast(); 615 extension->repeated_string_value->RemoveLast();
536 break; 616 break;
537 case WireFormatLite::CPPTYPE_MESSAGE: 617 case WireFormatLite::CPPTYPE_MESSAGE:
538 extension->repeated_message_value->RemoveLast(); 618 extension->repeated_message_value->RemoveLast();
539 break; 619 break;
540 } 620 }
541 } 621 }
542 622
623 MessageLite* ExtensionSet::ReleaseLast(int number) {
624 map<int, Extension>::iterator iter = extensions_.find(number);
625 GOOGLE_CHECK(iter != extensions_.end()) << "Index out-of-bounds (field is empt y).";
626
627 Extension* extension = &iter->second;
628 GOOGLE_DCHECK(extension->is_repeated);
629 GOOGLE_DCHECK(cpp_type(extension->type) == WireFormatLite::CPPTYPE_MESSAGE);
630 return extension->repeated_message_value->ReleaseLast();
631 }
632
543 void ExtensionSet::SwapElements(int number, int index1, int index2) { 633 void ExtensionSet::SwapElements(int number, int index1, int index2) {
544 map<int, Extension>::iterator iter = extensions_.find(number); 634 map<int, Extension>::iterator iter = extensions_.find(number);
545 GOOGLE_CHECK(iter != extensions_.end()) << "Index out-of-bounds (field is empt y)."; 635 GOOGLE_CHECK(iter != extensions_.end()) << "Index out-of-bounds (field is empt y).";
546 636
547 Extension* extension = &iter->second; 637 Extension* extension = &iter->second;
548 GOOGLE_DCHECK(extension->is_repeated); 638 GOOGLE_DCHECK(extension->is_repeated);
549 639
550 switch(cpp_type(extension->type)) { 640 switch(cpp_type(extension->type)) {
551 case WireFormatLite::CPPTYPE_INT32: 641 case WireFormatLite::CPPTYPE_INT32:
552 extension->repeated_int32_value->SwapElements(index1, index2); 642 extension->repeated_int32_value->SwapElements(index1, index2);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 iter != other.extensions_.end(); ++iter) { 685 iter != other.extensions_.end(); ++iter) {
596 const Extension& other_extension = iter->second; 686 const Extension& other_extension = iter->second;
597 687
598 if (other_extension.is_repeated) { 688 if (other_extension.is_repeated) {
599 Extension* extension; 689 Extension* extension;
600 bool is_new = MaybeNewExtension(iter->first, other_extension.descriptor, 690 bool is_new = MaybeNewExtension(iter->first, other_extension.descriptor,
601 &extension); 691 &extension);
602 if (is_new) { 692 if (is_new) {
603 // Extension did not already exist in set. 693 // Extension did not already exist in set.
604 extension->type = other_extension.type; 694 extension->type = other_extension.type;
695 extension->is_packed = other_extension.is_packed;
605 extension->is_repeated = true; 696 extension->is_repeated = true;
606 } else { 697 } else {
607 GOOGLE_DCHECK_EQ(extension->type, other_extension.type); 698 GOOGLE_DCHECK_EQ(extension->type, other_extension.type);
699 GOOGLE_DCHECK_EQ(extension->is_packed, other_extension.is_packed);
608 GOOGLE_DCHECK(extension->is_repeated); 700 GOOGLE_DCHECK(extension->is_repeated);
609 } 701 }
610 702
611 switch (cpp_type(other_extension.type)) { 703 switch (cpp_type(other_extension.type)) {
612 #define HANDLE_TYPE(UPPERCASE, LOWERCASE, REPEATED_TYPE) \ 704 #define HANDLE_TYPE(UPPERCASE, LOWERCASE, REPEATED_TYPE) \
613 case WireFormatLite::CPPTYPE_##UPPERCASE: \ 705 case WireFormatLite::CPPTYPE_##UPPERCASE: \
614 if (is_new) { \ 706 if (is_new) { \
615 extension->repeated_##LOWERCASE##_value = \ 707 extension->repeated_##LOWERCASE##_value = \
616 new REPEATED_TYPE; \ 708 new REPEATED_TYPE; \
617 } \ 709 } \
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 HANDLE_TYPE( FLOAT, float, Float); 760 HANDLE_TYPE( FLOAT, float, Float);
669 HANDLE_TYPE(DOUBLE, double, Double); 761 HANDLE_TYPE(DOUBLE, double, Double);
670 HANDLE_TYPE( BOOL, bool, Bool); 762 HANDLE_TYPE( BOOL, bool, Bool);
671 HANDLE_TYPE( ENUM, enum, Enum); 763 HANDLE_TYPE( ENUM, enum, Enum);
672 #undef HANDLE_TYPE 764 #undef HANDLE_TYPE
673 case WireFormatLite::CPPTYPE_STRING: 765 case WireFormatLite::CPPTYPE_STRING:
674 SetString(iter->first, other_extension.type, 766 SetString(iter->first, other_extension.type,
675 *other_extension.string_value, 767 *other_extension.string_value,
676 other_extension.descriptor); 768 other_extension.descriptor);
677 break; 769 break;
678 case WireFormatLite::CPPTYPE_MESSAGE: 770 case WireFormatLite::CPPTYPE_MESSAGE: {
679 MutableMessage(iter->first, other_extension.type, 771 Extension* extension;
680 *other_extension.message_value, 772 bool is_new = MaybeNewExtension(iter->first,
681 other_extension.descriptor) 773 other_extension.descriptor,
682 ->CheckTypeAndMergeFrom(*other_extension.message_value); 774 &extension);
775 if (is_new) {
776 extension->type = other_extension.type;
777 extension->is_packed = other_extension.is_packed;
778 extension->is_repeated = false;
779 if (other_extension.is_lazy) {
780 extension->is_lazy = true;
781 extension->lazymessage_value =
782 other_extension.lazymessage_value->New();
783 extension->lazymessage_value->MergeFrom(
784 *other_extension.lazymessage_value);
785 } else {
786 extension->is_lazy = false;
787 extension->message_value =
788 other_extension.message_value->New();
789 extension->message_value->CheckTypeAndMergeFrom(
790 *other_extension.message_value);
791 }
792 } else {
793 GOOGLE_DCHECK_EQ(extension->type, other_extension.type);
794 GOOGLE_DCHECK_EQ(extension->is_packed,other_extension.is_packed);
795 GOOGLE_DCHECK(!extension->is_repeated);
796 if (other_extension.is_lazy) {
797 if (extension->is_lazy) {
798 extension->lazymessage_value->MergeFrom(
799 *other_extension.lazymessage_value);
800 } else {
801 extension->message_value->CheckTypeAndMergeFrom(
802 other_extension.lazymessage_value->GetMessage(
803 *extension->message_value));
804 }
805 } else {
806 if (extension->is_lazy) {
807 extension->lazymessage_value->MutableMessage(
808 *other_extension.message_value)->CheckTypeAndMergeFrom(
809 *other_extension.message_value);
810 } else {
811 extension->message_value->CheckTypeAndMergeFrom(
812 *other_extension.message_value);
813 }
814 }
815 }
816 extension->is_cleared = false;
683 break; 817 break;
818 }
684 } 819 }
685 } 820 }
686 } 821 }
687 } 822 }
688 } 823 }
689 824
690 void ExtensionSet::Swap(ExtensionSet* x) { 825 void ExtensionSet::Swap(ExtensionSet* x) {
691 extensions_.swap(x->extensions_); 826 extensions_.swap(x->extensions_);
692 } 827 }
693 828
694 bool ExtensionSet::IsInitialized() const { 829 bool ExtensionSet::IsInitialized() const {
695 // Extensions are never required. However, we need to check that all 830 // Extensions are never required. However, we need to check that all
696 // embedded messages are initialized. 831 // embedded messages are initialized.
697 for (map<int, Extension>::const_iterator iter = extensions_.begin(); 832 for (map<int, Extension>::const_iterator iter = extensions_.begin();
698 iter != extensions_.end(); ++iter) { 833 iter != extensions_.end(); ++iter) {
699 const Extension& extension = iter->second; 834 const Extension& extension = iter->second;
700 if (cpp_type(extension.type) == WireFormatLite::CPPTYPE_MESSAGE) { 835 if (cpp_type(extension.type) == WireFormatLite::CPPTYPE_MESSAGE) {
701 if (extension.is_repeated) { 836 if (extension.is_repeated) {
702 for (int i = 0; i < extension.repeated_message_value->size(); i++) { 837 for (int i = 0; i < extension.repeated_message_value->size(); i++) {
703 if (!extension.repeated_message_value->Get(i).IsInitialized()) { 838 if (!extension.repeated_message_value->Get(i).IsInitialized()) {
704 return false; 839 return false;
705 } 840 }
706 } 841 }
707 } else { 842 } else {
708 if (!extension.is_cleared) { 843 if (!extension.is_cleared) {
709 if (!extension.message_value->IsInitialized()) return false; 844 if (extension.is_lazy) {
845 if (!extension.lazymessage_value->IsInitialized()) return false;
846 } else {
847 if (!extension.message_value->IsInitialized()) return false;
848 }
710 } 849 }
711 } 850 }
712 } 851 }
713 } 852 }
714 853
715 return true; 854 return true;
716 } 855 }
717 856
857 bool ExtensionSet::FindExtensionInfoFromTag(
858 uint32 tag, ExtensionFinder* extension_finder,
859 int* field_number, ExtensionInfo* extension) {
860 *field_number = WireFormatLite::GetTagFieldNumber(tag);
861 WireFormatLite::WireType wire_type = WireFormatLite::GetTagWireType(tag);
862
863 bool is_unknown;
864 if (!extension_finder->Find(*field_number, extension)) {
865 is_unknown = true;
866 } else if (extension->is_packed) {
867 is_unknown = (wire_type != WireFormatLite::WIRETYPE_LENGTH_DELIMITED);
868 } else {
869 WireFormatLite::WireType expected_wire_type =
870 WireFormatLite::WireTypeForFieldType(real_type(extension->type));
871 is_unknown = (wire_type != expected_wire_type);
872 }
873 return !is_unknown;
874 }
875
718 bool ExtensionSet::ParseField(uint32 tag, io::CodedInputStream* input, 876 bool ExtensionSet::ParseField(uint32 tag, io::CodedInputStream* input,
719 ExtensionFinder* extension_finder, 877 ExtensionFinder* extension_finder,
720 FieldSkipper* field_skipper) { 878 FieldSkipper* field_skipper) {
721 int number = WireFormatLite::GetTagFieldNumber(tag); 879 int number;
722 WireFormatLite::WireType wire_type = WireFormatLite::GetTagWireType(tag); 880 ExtensionInfo extension;
881 if (!FindExtensionInfoFromTag(tag, extension_finder, &number, &extension)) {
882 return field_skipper->SkipField(input, tag);
883 } else {
884 return ParseFieldWithExtensionInfo(number, extension, input, field_skipper);
885 }
886 }
723 887
724 ExtensionInfo extension; 888 bool ExtensionSet::ParseFieldWithExtensionInfo(
725 bool is_unknown; 889 int number, const ExtensionInfo& extension,
726 if (!extension_finder->Find(number, &extension)) { 890 io::CodedInputStream* input,
727 is_unknown = true; 891 FieldSkipper* field_skipper) {
728 } else if (extension.is_packed) { 892 if (extension.is_packed) {
729 is_unknown = (wire_type != WireFormatLite::WIRETYPE_LENGTH_DELIMITED);
730 } else {
731 WireFormatLite::WireType expected_wire_type =
732 WireFormatLite::WireTypeForFieldType(real_type(extension.type));
733 is_unknown = (wire_type != expected_wire_type);
734 }
735
736 if (is_unknown) {
737 field_skipper->SkipField(input, tag);
738 } else if (extension.is_packed) {
739 uint32 size; 893 uint32 size;
740 if (!input->ReadVarint32(&size)) return false; 894 if (!input->ReadVarint32(&size)) return false;
741 io::CodedInputStream::Limit limit = input->PushLimit(size); 895 io::CodedInputStream::Limit limit = input->PushLimit(size);
742 896
743 switch (extension.type) { 897 switch (extension.type) {
744 #define HANDLE_TYPE(UPPERCASE, CPP_CAMELCASE, CPP_LOWERCASE) \ 898 #define HANDLE_TYPE(UPPERCASE, CPP_CAMELCASE, CPP_LOWERCASE) \
745 case WireFormatLite::TYPE_##UPPERCASE: \ 899 case WireFormatLite::TYPE_##UPPERCASE: \
746 while (input->BytesUntilLimit() > 0) { \ 900 while (input->BytesUntilLimit() > 0) { \
747 CPP_LOWERCASE value; \ 901 CPP_LOWERCASE value; \
748 if (!WireFormatLite::ReadPrimitive< \ 902 if (!WireFormatLite::ReadPrimitive< \
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 string* value = extension.is_repeated ? 999 string* value = extension.is_repeated ?
846 AddString(number, WireFormatLite::TYPE_STRING, extension.descriptor) : 1000 AddString(number, WireFormatLite::TYPE_STRING, extension.descriptor) :
847 MutableString(number, WireFormatLite::TYPE_STRING, 1001 MutableString(number, WireFormatLite::TYPE_STRING,
848 extension.descriptor); 1002 extension.descriptor);
849 if (!WireFormatLite::ReadString(input, value)) return false; 1003 if (!WireFormatLite::ReadString(input, value)) return false;
850 break; 1004 break;
851 } 1005 }
852 1006
853 case WireFormatLite::TYPE_BYTES: { 1007 case WireFormatLite::TYPE_BYTES: {
854 string* value = extension.is_repeated ? 1008 string* value = extension.is_repeated ?
855 AddString(number, WireFormatLite::TYPE_STRING, extension.descriptor) : 1009 AddString(number, WireFormatLite::TYPE_BYTES, extension.descriptor) :
856 MutableString(number, WireFormatLite::TYPE_STRING, 1010 MutableString(number, WireFormatLite::TYPE_BYTES,
857 extension.descriptor); 1011 extension.descriptor);
858 if (!WireFormatLite::ReadBytes(input, value)) return false; 1012 if (!WireFormatLite::ReadBytes(input, value)) return false;
859 break; 1013 break;
860 } 1014 }
861 1015
862 case WireFormatLite::TYPE_GROUP: { 1016 case WireFormatLite::TYPE_GROUP: {
863 MessageLite* value = extension.is_repeated ? 1017 MessageLite* value = extension.is_repeated ?
864 AddMessage(number, WireFormatLite::TYPE_GROUP, 1018 AddMessage(number, WireFormatLite::TYPE_GROUP,
865 *extension.message_prototype, extension.descriptor) : 1019 *extension.message_prototype, extension.descriptor) :
866 MutableMessage(number, WireFormatLite::TYPE_GROUP, 1020 MutableMessage(number, WireFormatLite::TYPE_GROUP,
(...skipping 23 matching lines...) Expand all
890 FieldSkipper skipper(unknown_fields); 1044 FieldSkipper skipper(unknown_fields);
891 GeneratedExtensionFinder finder(containing_type); 1045 GeneratedExtensionFinder finder(containing_type);
892 return ParseField(tag, input, &finder, &skipper); 1046 return ParseField(tag, input, &finder, &skipper);
893 } 1047 }
894 1048
895 // Defined in extension_set_heavy.cc. 1049 // Defined in extension_set_heavy.cc.
896 // bool ExtensionSet::ParseFieldHeavy(uint32 tag, io::CodedInputStream* input, 1050 // bool ExtensionSet::ParseFieldHeavy(uint32 tag, io::CodedInputStream* input,
897 // const Message* containing_type, 1051 // const Message* containing_type,
898 // UnknownFieldSet* unknown_fields) 1052 // UnknownFieldSet* unknown_fields)
899 1053
900 bool ExtensionSet::ParseMessageSet(io::CodedInputStream* input,
901 ExtensionFinder* extension_finder,
902 FieldSkipper* field_skipper) {
903 while (true) {
904 uint32 tag = input->ReadTag();
905 switch (tag) {
906 case 0:
907 return true;
908 case WireFormatLite::kMessageSetItemStartTag:
909 if (!ParseMessageSetItem(input, extension_finder, field_skipper)) {
910 return false;
911 }
912 break;
913 default:
914 if (!ParseField(tag, input, extension_finder, field_skipper)) {
915 return false;
916 }
917 break;
918 }
919 }
920 }
921
922 bool ExtensionSet::ParseMessageSet(io::CodedInputStream* input,
923 const MessageLite* containing_type,
924 UnknownFieldSet* unknown_fields) {
925 FieldSkipper skipper(unknown_fields);
926 GeneratedExtensionFinder finder(containing_type);
927 return ParseMessageSet(input, &finder, &skipper);
928 }
929
930 // Defined in extension_set_heavy.cc. 1054 // Defined in extension_set_heavy.cc.
931 // bool ExtensionSet::ParseMessageSetHeavy(io::CodedInputStream* input, 1055 // bool ExtensionSet::ParseMessageSetHeavy(io::CodedInputStream* input,
932 // const Message* containing_type, 1056 // const Message* containing_type,
933 // UnknownFieldSet* unknown_fields); 1057 // UnknownFieldSet* unknown_fields);
934 1058
935 bool ExtensionSet::ParseMessageSetItem(io::CodedInputStream* input,
936 ExtensionFinder* extension_finder,
937 FieldSkipper* field_skipper) {
938 // TODO(kenton): It would be nice to share code between this and
939 // WireFormatLite::ParseAndMergeMessageSetItem(), but I think the
940 // differences would be hard to factor out.
941
942 // This method parses a group which should contain two fields:
943 // required int32 type_id = 2;
944 // required data message = 3;
945
946 // Once we see a type_id, we'll construct a fake tag for this extension
947 // which is the tag it would have had under the proto2 extensions wire
948 // format.
949 uint32 fake_tag = 0;
950
951 // If we see message data before the type_id, we'll append it to this so
952 // we can parse it later. This will probably never happen in practice,
953 // as no MessageSet encoder I know of writes the message before the type ID.
954 // But, it's technically valid so we should allow it.
955 // TODO(kenton): Use a Cord instead? Do I care?
956 string message_data;
957
958 while (true) {
959 uint32 tag = input->ReadTag();
960 if (tag == 0) return false;
961
962 switch (tag) {
963 case WireFormatLite::kMessageSetTypeIdTag: {
964 uint32 type_id;
965 if (!input->ReadVarint32(&type_id)) return false;
966 fake_tag = WireFormatLite::MakeTag(type_id,
967 WireFormatLite::WIRETYPE_LENGTH_DELIMITED);
968
969 if (!message_data.empty()) {
970 // We saw some message data before the type_id. Have to parse it
971 // now.
972 io::CodedInputStream sub_input(
973 reinterpret_cast<const uint8*>(message_data.data()),
974 message_data.size());
975 if (!ParseField(fake_tag, &sub_input,
976 extension_finder, field_skipper)) {
977 return false;
978 }
979 message_data.clear();
980 }
981
982 break;
983 }
984
985 case WireFormatLite::kMessageSetMessageTag: {
986 if (fake_tag == 0) {
987 // We haven't seen a type_id yet. Append this data to message_data.
988 string temp;
989 uint32 length;
990 if (!input->ReadVarint32(&length)) return false;
991 if (!input->ReadString(&temp, length)) return false;
992 message_data.append(temp);
993 } else {
994 // Already saw type_id, so we can parse this directly.
995 if (!ParseField(fake_tag, input,
996 extension_finder, field_skipper)) {
997 return false;
998 }
999 }
1000
1001 break;
1002 }
1003
1004 case WireFormatLite::kMessageSetItemEndTag: {
1005 return true;
1006 }
1007
1008 default: {
1009 if (!field_skipper->SkipField(input, tag)) return false;
1010 }
1011 }
1012 }
1013 }
1014
1015 void ExtensionSet::SerializeWithCachedSizes( 1059 void ExtensionSet::SerializeWithCachedSizes(
1016 int start_field_number, int end_field_number, 1060 int start_field_number, int end_field_number,
1017 io::CodedOutputStream* output) const { 1061 io::CodedOutputStream* output) const {
1018 map<int, Extension>::const_iterator iter; 1062 map<int, Extension>::const_iterator iter;
1019 for (iter = extensions_.lower_bound(start_field_number); 1063 for (iter = extensions_.lower_bound(start_field_number);
1020 iter != extensions_.end() && iter->first < end_field_number; 1064 iter != extensions_.end() && iter->first < end_field_number;
1021 ++iter) { 1065 ++iter) {
1022 iter->second.SerializeFieldWithCachedSizes(iter->first, output); 1066 iter->second.SerializeFieldWithCachedSizes(iter->first, output);
1023 } 1067 }
1024 } 1068 }
1025 1069
1026 void ExtensionSet::SerializeMessageSetWithCachedSizes(
1027 io::CodedOutputStream* output) const {
1028 map<int, Extension>::const_iterator iter;
1029 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) {
1030 iter->second.SerializeMessageSetItemWithCachedSizes(iter->first, output);
1031 }
1032 }
1033
1034 int ExtensionSet::ByteSize() const { 1070 int ExtensionSet::ByteSize() const {
1035 int total_size = 0; 1071 int total_size = 0;
1036 1072
1037 for (map<int, Extension>::const_iterator iter = extensions_.begin(); 1073 for (map<int, Extension>::const_iterator iter = extensions_.begin();
1038 iter != extensions_.end(); ++iter) { 1074 iter != extensions_.end(); ++iter) {
1039 total_size += iter->second.ByteSize(iter->first); 1075 total_size += iter->second.ByteSize(iter->first);
1040 } 1076 }
1041 1077
1042 return total_size; 1078 return total_size;
1043 } 1079 }
1044 1080
1045 int ExtensionSet::MessageSetByteSize() const {
1046 int total_size = 0;
1047
1048 for (map<int, Extension>::const_iterator iter = extensions_.begin();
1049 iter != extensions_.end(); ++iter) {
1050 total_size += iter->second.MessageSetItemByteSize(iter->first);
1051 }
1052
1053 return total_size;
1054 }
1055
1056 // Defined in extension_set_heavy.cc. 1081 // Defined in extension_set_heavy.cc.
1057 // int ExtensionSet::SpaceUsedExcludingSelf() const 1082 // int ExtensionSet::SpaceUsedExcludingSelf() const
1058 1083
1059 bool ExtensionSet::MaybeNewExtension(int number, 1084 bool ExtensionSet::MaybeNewExtension(int number,
1060 const FieldDescriptor* descriptor, 1085 const FieldDescriptor* descriptor,
1061 Extension** result) { 1086 Extension** result) {
1062 pair<map<int, Extension>::iterator, bool> insert_result = 1087 pair<map<int, Extension>::iterator, bool> insert_result =
1063 extensions_.insert(make_pair(number, Extension())); 1088 extensions_.insert(make_pair(number, Extension()));
1064 *result = &insert_result.first->second; 1089 *result = &insert_result.first->second;
1065 (*result)->descriptor = descriptor; 1090 (*result)->descriptor = descriptor;
(...skipping 23 matching lines...) Expand all
1089 HANDLE_TYPE(MESSAGE, message); 1114 HANDLE_TYPE(MESSAGE, message);
1090 #undef HANDLE_TYPE 1115 #undef HANDLE_TYPE
1091 } 1116 }
1092 } else { 1117 } else {
1093 if (!is_cleared) { 1118 if (!is_cleared) {
1094 switch (cpp_type(type)) { 1119 switch (cpp_type(type)) {
1095 case WireFormatLite::CPPTYPE_STRING: 1120 case WireFormatLite::CPPTYPE_STRING:
1096 string_value->clear(); 1121 string_value->clear();
1097 break; 1122 break;
1098 case WireFormatLite::CPPTYPE_MESSAGE: 1123 case WireFormatLite::CPPTYPE_MESSAGE:
1099 message_value->Clear(); 1124 if (is_lazy) {
1125 lazymessage_value->Clear();
1126 } else {
1127 message_value->Clear();
1128 }
1100 break; 1129 break;
1101 default: 1130 default:
1102 // No need to do anything. Get*() will return the default value 1131 // No need to do anything. Get*() will return the default value
1103 // as long as is_cleared is true and Set*() will overwrite the 1132 // as long as is_cleared is true and Set*() will overwrite the
1104 // previous value. 1133 // previous value.
1105 break; 1134 break;
1106 } 1135 }
1107 1136
1108 is_cleared = true; 1137 is_cleared = true;
1109 } 1138 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 HANDLE_TYPE( FIXED64, Fixed64, uint64_value); 1230 HANDLE_TYPE( FIXED64, Fixed64, uint64_value);
1202 HANDLE_TYPE(SFIXED32, SFixed32, int32_value); 1231 HANDLE_TYPE(SFIXED32, SFixed32, int32_value);
1203 HANDLE_TYPE(SFIXED64, SFixed64, int64_value); 1232 HANDLE_TYPE(SFIXED64, SFixed64, int64_value);
1204 HANDLE_TYPE( FLOAT, Float, float_value); 1233 HANDLE_TYPE( FLOAT, Float, float_value);
1205 HANDLE_TYPE( DOUBLE, Double, double_value); 1234 HANDLE_TYPE( DOUBLE, Double, double_value);
1206 HANDLE_TYPE( BOOL, Bool, bool_value); 1235 HANDLE_TYPE( BOOL, Bool, bool_value);
1207 HANDLE_TYPE( STRING, String, *string_value); 1236 HANDLE_TYPE( STRING, String, *string_value);
1208 HANDLE_TYPE( BYTES, Bytes, *string_value); 1237 HANDLE_TYPE( BYTES, Bytes, *string_value);
1209 HANDLE_TYPE( ENUM, Enum, enum_value); 1238 HANDLE_TYPE( ENUM, Enum, enum_value);
1210 HANDLE_TYPE( GROUP, Group, *message_value); 1239 HANDLE_TYPE( GROUP, Group, *message_value);
1211 HANDLE_TYPE( MESSAGE, Message, *message_value);
1212 #undef HANDLE_TYPE 1240 #undef HANDLE_TYPE
1241 case WireFormatLite::TYPE_MESSAGE:
1242 if (is_lazy) {
1243 lazymessage_value->WriteMessage(number, output);
1244 } else {
1245 WireFormatLite::WriteMessage(number, *message_value, output);
1246 }
1247 break;
1213 } 1248 }
1214 } 1249 }
1215 } 1250 }
1216 1251
1217 void ExtensionSet::Extension::SerializeMessageSetItemWithCachedSizes(
1218 int number,
1219 io::CodedOutputStream* output) const {
1220 if (type != WireFormatLite::TYPE_MESSAGE || is_repeated) {
1221 // Not a valid MessageSet extension, but serialize it the normal way.
1222 SerializeFieldWithCachedSizes(number, output);
1223 return;
1224 }
1225
1226 if (is_cleared) return;
1227
1228 // Start group.
1229 output->WriteTag(WireFormatLite::kMessageSetItemStartTag);
1230
1231 // Write type ID.
1232 WireFormatLite::WriteUInt32(WireFormatLite::kMessageSetTypeIdNumber,
1233 number,
1234 output);
1235 // Write message.
1236 WireFormatLite::WriteMessageMaybeToArray(
1237 WireFormatLite::kMessageSetMessageNumber,
1238 *message_value,
1239 output);
1240
1241 // End group.
1242 output->WriteTag(WireFormatLite::kMessageSetItemEndTag);
1243 }
1244
1245 int ExtensionSet::Extension::ByteSize(int number) const { 1252 int ExtensionSet::Extension::ByteSize(int number) const {
1246 int result = 0; 1253 int result = 0;
1247 1254
1248 if (is_repeated) { 1255 if (is_repeated) {
1249 if (is_packed) { 1256 if (is_packed) {
1250 switch (real_type(type)) { 1257 switch (real_type(type)) {
1251 #define HANDLE_TYPE(UPPERCASE, CAMELCASE, LOWERCASE) \ 1258 #define HANDLE_TYPE(UPPERCASE, CAMELCASE, LOWERCASE) \
1252 case WireFormatLite::TYPE_##UPPERCASE: \ 1259 case WireFormatLite::TYPE_##UPPERCASE: \
1253 for (int i = 0; i < repeated_##LOWERCASE##_value->size(); i++) { \ 1260 for (int i = 0; i < repeated_##LOWERCASE##_value->size(); i++) { \
1254 result += WireFormatLite::CAMELCASE##Size( \ 1261 result += WireFormatLite::CAMELCASE##Size( \
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 HANDLE_TYPE( INT32, Int32, int32_value); 1355 HANDLE_TYPE( INT32, Int32, int32_value);
1349 HANDLE_TYPE( INT64, Int64, int64_value); 1356 HANDLE_TYPE( INT64, Int64, int64_value);
1350 HANDLE_TYPE( UINT32, UInt32, uint32_value); 1357 HANDLE_TYPE( UINT32, UInt32, uint32_value);
1351 HANDLE_TYPE( UINT64, UInt64, uint64_value); 1358 HANDLE_TYPE( UINT64, UInt64, uint64_value);
1352 HANDLE_TYPE( SINT32, SInt32, int32_value); 1359 HANDLE_TYPE( SINT32, SInt32, int32_value);
1353 HANDLE_TYPE( SINT64, SInt64, int64_value); 1360 HANDLE_TYPE( SINT64, SInt64, int64_value);
1354 HANDLE_TYPE( STRING, String, *string_value); 1361 HANDLE_TYPE( STRING, String, *string_value);
1355 HANDLE_TYPE( BYTES, Bytes, *string_value); 1362 HANDLE_TYPE( BYTES, Bytes, *string_value);
1356 HANDLE_TYPE( ENUM, Enum, enum_value); 1363 HANDLE_TYPE( ENUM, Enum, enum_value);
1357 HANDLE_TYPE( GROUP, Group, *message_value); 1364 HANDLE_TYPE( GROUP, Group, *message_value);
1358 HANDLE_TYPE( MESSAGE, Message, *message_value);
1359 #undef HANDLE_TYPE 1365 #undef HANDLE_TYPE
1366 case WireFormatLite::TYPE_MESSAGE: {
1367 if (is_lazy) {
1368 int size = lazymessage_value->ByteSize();
1369 result += io::CodedOutputStream::VarintSize32(size) + size;
1370 } else {
1371 result += WireFormatLite::MessageSize(*message_value);
1372 }
1373 break;
1374 }
1360 1375
1361 // Stuff with fixed size. 1376 // Stuff with fixed size.
1362 #define HANDLE_TYPE(UPPERCASE, CAMELCASE) \ 1377 #define HANDLE_TYPE(UPPERCASE, CAMELCASE) \
1363 case WireFormatLite::TYPE_##UPPERCASE: \ 1378 case WireFormatLite::TYPE_##UPPERCASE: \
1364 result += WireFormatLite::k##CAMELCASE##Size; \ 1379 result += WireFormatLite::k##CAMELCASE##Size; \
1365 break 1380 break
1366 HANDLE_TYPE( FIXED32, Fixed32); 1381 HANDLE_TYPE( FIXED32, Fixed32);
1367 HANDLE_TYPE( FIXED64, Fixed64); 1382 HANDLE_TYPE( FIXED64, Fixed64);
1368 HANDLE_TYPE(SFIXED32, SFixed32); 1383 HANDLE_TYPE(SFIXED32, SFixed32);
1369 HANDLE_TYPE(SFIXED64, SFixed64); 1384 HANDLE_TYPE(SFIXED64, SFixed64);
1370 HANDLE_TYPE( FLOAT, Float); 1385 HANDLE_TYPE( FLOAT, Float);
1371 HANDLE_TYPE( DOUBLE, Double); 1386 HANDLE_TYPE( DOUBLE, Double);
1372 HANDLE_TYPE( BOOL, Bool); 1387 HANDLE_TYPE( BOOL, Bool);
1373 #undef HANDLE_TYPE 1388 #undef HANDLE_TYPE
1374 } 1389 }
1375 } 1390 }
1376 1391
1377 return result; 1392 return result;
1378 } 1393 }
1379 1394
1380 int ExtensionSet::Extension::MessageSetItemByteSize(int number) const {
1381 if (type != WireFormatLite::TYPE_MESSAGE || is_repeated) {
1382 // Not a valid MessageSet extension, but compute the byte size for it the
1383 // normal way.
1384 return ByteSize(number);
1385 }
1386
1387 if (is_cleared) return 0;
1388
1389 int our_size = WireFormatLite::kMessageSetItemTagsSize;
1390
1391 // type_id
1392 our_size += io::CodedOutputStream::VarintSize32(number);
1393
1394 // message
1395 int message_size = message_value->ByteSize();
1396
1397 our_size += io::CodedOutputStream::VarintSize32(message_size);
1398 our_size += message_size;
1399
1400 return our_size;
1401 }
1402
1403 int ExtensionSet::Extension::GetSize() const { 1395 int ExtensionSet::Extension::GetSize() const {
1404 GOOGLE_DCHECK(is_repeated); 1396 GOOGLE_DCHECK(is_repeated);
1405 switch (cpp_type(type)) { 1397 switch (cpp_type(type)) {
1406 #define HANDLE_TYPE(UPPERCASE, LOWERCASE) \ 1398 #define HANDLE_TYPE(UPPERCASE, LOWERCASE) \
1407 case WireFormatLite::CPPTYPE_##UPPERCASE: \ 1399 case WireFormatLite::CPPTYPE_##UPPERCASE: \
1408 return repeated_##LOWERCASE##_value->size() 1400 return repeated_##LOWERCASE##_value->size()
1409 1401
1410 HANDLE_TYPE( INT32, int32); 1402 HANDLE_TYPE( INT32, int32);
1411 HANDLE_TYPE( INT64, int64); 1403 HANDLE_TYPE( INT64, int64);
1412 HANDLE_TYPE( UINT32, uint32); 1404 HANDLE_TYPE( UINT32, uint32);
(...skipping 30 matching lines...) Expand all
1443 HANDLE_TYPE( STRING, string); 1435 HANDLE_TYPE( STRING, string);
1444 HANDLE_TYPE(MESSAGE, message); 1436 HANDLE_TYPE(MESSAGE, message);
1445 #undef HANDLE_TYPE 1437 #undef HANDLE_TYPE
1446 } 1438 }
1447 } else { 1439 } else {
1448 switch (cpp_type(type)) { 1440 switch (cpp_type(type)) {
1449 case WireFormatLite::CPPTYPE_STRING: 1441 case WireFormatLite::CPPTYPE_STRING:
1450 delete string_value; 1442 delete string_value;
1451 break; 1443 break;
1452 case WireFormatLite::CPPTYPE_MESSAGE: 1444 case WireFormatLite::CPPTYPE_MESSAGE:
1453 delete message_value; 1445 if (is_lazy) {
1446 delete lazymessage_value;
1447 } else {
1448 delete message_value;
1449 }
1454 break; 1450 break;
1455 default: 1451 default:
1456 break; 1452 break;
1457 } 1453 }
1458 } 1454 }
1459 } 1455 }
1460 1456
1461 // Defined in extension_set_heavy.cc. 1457 // Defined in extension_set_heavy.cc.
1462 // int ExtensionSet::Extension::SpaceUsedExcludingSelf() const 1458 // int ExtensionSet::Extension::SpaceUsedExcludingSelf() const
1463 1459
1464 } // namespace internal 1460 } // namespace internal
1465 } // namespace protobuf 1461 } // namespace protobuf
1466 } // namespace google 1462 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698