diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 75418982ea..d38a2242e0 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -918,7 +918,7 @@ bool HasNonZeroDefaultValue(const FieldDescriptor* field) { string BuildFlagsString(const FlagType flag_type, const std::vector& strings) { - if (strings.size() == 0) { + if (strings.empty()) { return GetZeroEnumNameForFlagType(flag_type); } else if (strings.size() == 1) { return strings[0]; @@ -945,7 +945,7 @@ string BuildCommentsString(const SourceLocation& location, lines.pop_back(); } // If there are no comments, just return an empty string. - if (lines.size() == 0) { + if (lines.empty()) { return ""; } @@ -1405,7 +1405,7 @@ string DirectDecodeString(const string& str) { // static string TextFormatDecodeData::DecodeDataForString(const string& input_for_decode, const string& desired_output) { - if ((input_for_decode.size() == 0) || (desired_output.size() == 0)) { + if (input_for_decode.empty() || desired_output.empty()) { std::cerr << "error: got empty string for making TextFormat data, input: \"" << input_for_decode << "\", desired: \"" << desired_output << "\"." << std::endl; @@ -1515,7 +1515,7 @@ bool Parser::ParseLoop() { ++line_; RemoveComment(&line); TrimWhitespace(&line); - if (line.size() == 0) { + if (line.empty()) { continue; // Blank line. } if (!line_consumer_->ConsumeLine(line, &error_str_)) { @@ -1622,7 +1622,7 @@ void ImportWriter::Print(io::Printer* printer) const { bool add_blank_line = false; - if (protobuf_framework_imports_.size() > 0) { + if (!protobuf_framework_imports_.empty()) { const string framework_name(ProtobufLibraryFrameworkName); const string cpp_symbol(ProtobufFrameworkImportSymbol(framework_name)); @@ -1650,7 +1650,7 @@ void ImportWriter::Print(io::Printer* printer) const { add_blank_line = true; } - if (other_framework_imports_.size() > 0) { + if (!other_framework_imports_.empty()) { if (add_blank_line) { printer->Print("\n"); } @@ -1665,7 +1665,7 @@ void ImportWriter::Print(io::Printer* printer) const { add_blank_line = true; } - if (other_imports_.size() > 0) { + if (!other_imports_.empty()) { if (add_blank_line) { printer->Print("\n"); } @@ -1717,7 +1717,7 @@ bool ImportWriter::ProtoFrameworkCollector::ConsumeLine( StringPiece proto_file = proto_file_list.substr(start, offset - start); TrimWhitespace(&proto_file); - if (proto_file.size() != 0) { + if (!proto_file.empty()) { std::map::iterator existing_entry = map_->find(string(proto_file)); if (existing_entry != map_->end()) { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.cc b/src/google/protobuf/compiler/objectivec/objectivec_message.cc index 2a0e40231d..5ab5fd5b55 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.cc @@ -50,9 +50,6 @@ namespace protobuf { namespace compiler { namespace objectivec { -using internal::WireFormat; -using internal::WireFormatLite; - namespace { struct FieldOrderingByNumber { inline bool operator()(const FieldDescriptor* a, @@ -417,6 +414,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { SortFieldsByStorageSize(descriptor_)); std::vector sorted_extensions; + sorted_extensions.reserve(descriptor_->extension_range_count()); for (int i = 0; i < descriptor_->extension_range_count(); ++i) { sorted_extensions.push_back(descriptor_->extension_range(i)); } @@ -536,7 +534,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { " fieldCount:$fields_count$\n" " storageSize:sizeof($classname$__storage_)\n" " flags:$init_flags$];\n"); - if (oneof_generators_.size() != 0) { + if (!oneof_generators_.empty()) { printer->Print( " static const char *oneofs[] = {\n"); for (const auto& generator : oneof_generators_) { @@ -567,7 +565,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { " [localDescriptor setupExtraTextInfo:extraTextFormatInfo];\n" "#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS\n"); } - if (sorted_extensions.size() != 0) { + if (!sorted_extensions.empty()) { printer->Print( " static const GPBExtensionRange ranges[] = {\n"); for (int i = 0; i < sorted_extensions.size(); i++) { @@ -589,7 +587,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { } string suffix_added; ClassName(descriptor_, &suffix_added); - if (suffix_added.size() > 0) { + if (!suffix_added.empty()) { printer->Print( " [localDescriptor setupMessageClassNameSuffix:@\"$suffix$\"];\n", "suffix", suffix_added);