Browse Source

Fixed some lint errors seen in google3. (#6520)

Joshua Haberman 6 years ago
parent
commit
ee4f2492ea

+ 1 - 1
src/google/protobuf/compiler/csharp/csharp_helpers.cc

@@ -297,7 +297,7 @@ uint GetGroupEndTag(const Descriptor* descriptor) {
 
 
 std::string ToCSharpName(const std::string& name, const FileDescriptor* file) {
 std::string ToCSharpName(const std::string& name, const FileDescriptor* file) {
   std::string result = GetFileNamespace(file);
   std::string result = GetFileNamespace(file);
-  if (result != "") {
+  if (!result.empty()) {
     result += '.';
     result += '.';
   }
   }
   string classname;
   string classname;

+ 3 - 0
src/google/protobuf/compiler/csharp/csharp_reflection_class.cc

@@ -261,6 +261,7 @@ void ReflectionClassGenerator::WriteGeneratedCodeInfo(const Descriptor* descript
   // Fields
   // Fields
   if (descriptor->field_count() > 0) {
   if (descriptor->field_count() > 0) {
       std::vector<std::string> fields;
       std::vector<std::string> fields;
+      fields.reserve(descriptor->field_count());
       for (int i = 0; i < descriptor->field_count(); i++) {
       for (int i = 0; i < descriptor->field_count(); i++) {
           fields.push_back(GetPropertyName(descriptor->field(i)));
           fields.push_back(GetPropertyName(descriptor->field(i)));
       }
       }
@@ -273,6 +274,7 @@ void ReflectionClassGenerator::WriteGeneratedCodeInfo(const Descriptor* descript
   // Oneofs
   // Oneofs
   if (descriptor->oneof_decl_count() > 0) {
   if (descriptor->oneof_decl_count() > 0) {
       std::vector<std::string> oneofs;
       std::vector<std::string> oneofs;
+      oneofs.reserve(descriptor->oneof_decl_count());
       for (int i = 0; i < descriptor->oneof_decl_count(); i++) {
       for (int i = 0; i < descriptor->oneof_decl_count(); i++) {
           oneofs.push_back(UnderscoresToCamelCase(descriptor->oneof_decl(i)->name(), true));
           oneofs.push_back(UnderscoresToCamelCase(descriptor->oneof_decl(i)->name(), true));
       }
       }
@@ -285,6 +287,7 @@ void ReflectionClassGenerator::WriteGeneratedCodeInfo(const Descriptor* descript
   // Nested enums
   // Nested enums
   if (descriptor->enum_type_count() > 0) {
   if (descriptor->enum_type_count() > 0) {
       std::vector<std::string> enums;
       std::vector<std::string> enums;
+      enums.reserve(descriptor->enum_type_count());
       for (int i = 0; i < descriptor->enum_type_count(); i++) {
       for (int i = 0; i < descriptor->enum_type_count(); i++) {
           enums.push_back(GetClassName(descriptor->enum_type(i)));
           enums.push_back(GetClassName(descriptor->enum_type(i)));
       }
       }

+ 23 - 28
src/google/protobuf/compiler/php/php_generator.cc

@@ -88,7 +88,6 @@ std::string GeneratedMetadataFileName(const FileDescriptor* file,
 std::string LabelForField(FieldDescriptor* field);
 std::string LabelForField(FieldDescriptor* field);
 std::string TypeName(FieldDescriptor* field);
 std::string TypeName(FieldDescriptor* field);
 std::string UnderscoresToCamelCase(const string& name, bool cap_first_letter);
 std::string UnderscoresToCamelCase(const string& name, bool cap_first_letter);
-std::string EscapeDollor(const string& to_escape);
 std::string BinaryToHex(const string& binary);
 std::string BinaryToHex(const string& binary);
 void Indent(io::Printer* printer);
 void Indent(io::Printer* printer);
 void Outdent(io::Printer* printer);
 void Outdent(io::Printer* printer);
@@ -153,7 +152,7 @@ template <typename DescriptorType>
 std::string ClassNamePrefix(const string& classname,
 std::string ClassNamePrefix(const string& classname,
                             const DescriptorType* desc) {
                             const DescriptorType* desc) {
   const string& prefix = (desc->file()->options()).php_class_prefix();
   const string& prefix = (desc->file()->options()).php_class_prefix();
-  if (prefix != "") {
+  if (!prefix.empty()) {
     return prefix;
     return prefix;
   }
   }
 
 
@@ -244,13 +243,13 @@ template <typename DescriptorType>
 std::string RootPhpNamespace(const DescriptorType* desc, bool is_descriptor) {
 std::string RootPhpNamespace(const DescriptorType* desc, bool is_descriptor) {
   if (desc->file()->options().has_php_namespace()) {
   if (desc->file()->options().has_php_namespace()) {
     const string& php_namespace = desc->file()->options().php_namespace();
     const string& php_namespace = desc->file()->options().php_namespace();
-    if (php_namespace != "") {
+    if (!php_namespace.empty()) {
       return php_namespace;
       return php_namespace;
     }
     }
     return "";
     return "";
   }
   }
 
 
-  if (desc->file()->package() != "") {
+  if (!desc->file()->package().empty()) {
     return PhpName(desc->file()->package(), is_descriptor);
     return PhpName(desc->file()->package(), is_descriptor);
   }
   }
   return "";
   return "";
@@ -260,7 +259,7 @@ template <typename DescriptorType>
 std::string FullClassName(const DescriptorType* desc, bool is_descriptor) {
 std::string FullClassName(const DescriptorType* desc, bool is_descriptor) {
   string classname = GeneratedClassNameImpl(desc);
   string classname = GeneratedClassNameImpl(desc);
   string php_namespace = RootPhpNamespace(desc, is_descriptor);
   string php_namespace = RootPhpNamespace(desc, is_descriptor);
-  if (php_namespace != "") {
+  if (!php_namespace.empty()) {
     return php_namespace + "\\" + classname;
     return php_namespace + "\\" + classname;
   }
   }
   return classname;
   return classname;
@@ -270,7 +269,7 @@ template <typename DescriptorType>
 std::string LegacyFullClassName(const DescriptorType* desc, bool is_descriptor) {
 std::string LegacyFullClassName(const DescriptorType* desc, bool is_descriptor) {
   string classname = LegacyGeneratedClassName(desc);
   string classname = LegacyGeneratedClassName(desc);
   string php_namespace = RootPhpNamespace(desc, is_descriptor);
   string php_namespace = RootPhpNamespace(desc, is_descriptor);
-  if (php_namespace != "") {
+  if (!php_namespace.empty()) {
     return php_namespace + "\\" + classname;
     return php_namespace + "\\" + classname;
   }
   }
   return classname;
   return classname;
@@ -352,7 +351,7 @@ std::string GeneratedMetadataFileName(const FileDescriptor* file,
   if (file->options().has_php_metadata_namespace()) {
   if (file->options().has_php_metadata_namespace()) {
     const string& php_metadata_namespace =
     const string& php_metadata_namespace =
         file->options().php_metadata_namespace();
         file->options().php_metadata_namespace();
-    if (php_metadata_namespace != "" && php_metadata_namespace != "\\") {
+    if (!php_metadata_namespace.empty() && php_metadata_namespace != "\\") {
       result += php_metadata_namespace;
       result += php_metadata_namespace;
       std::replace(result.begin(), result.end(), '\\', '/');
       std::replace(result.begin(), result.end(), '\\', '/');
       if (result.at(result.size() - 1) != '/') {
       if (result.at(result.size() - 1) != '/') {
@@ -552,45 +551,41 @@ std::string EnumOrMessageSuffix(
 
 
 // Converts a name to camel-case. If cap_first_letter is true, capitalize the
 // Converts a name to camel-case. If cap_first_letter is true, capitalize the
 // first letter.
 // first letter.
-std::string UnderscoresToCamelCase(const string& input, bool cap_first_letter) {
+std::string UnderscoresToCamelCase(const string& name, bool cap_first_letter) {
   std::string result;
   std::string result;
-  for (int i = 0; i < input.size(); i++) {
-    if ('a' <= input[i] && input[i] <= 'z') {
+  for (int i = 0; i < name.size(); i++) {
+    if ('a' <= name[i] && name[i] <= 'z') {
       if (cap_first_letter) {
       if (cap_first_letter) {
-        result += input[i] + ('A' - 'a');
+        result += name[i] + ('A' - 'a');
       } else {
       } else {
-        result += input[i];
+        result += name[i];
       }
       }
       cap_first_letter = false;
       cap_first_letter = false;
-    } else if ('A' <= input[i] && input[i] <= 'Z') {
+    } else if ('A' <= name[i] && name[i] <= 'Z') {
       if (i == 0 && !cap_first_letter) {
       if (i == 0 && !cap_first_letter) {
         // Force first letter to lower-case unless explicitly told to
         // Force first letter to lower-case unless explicitly told to
         // capitalize it.
         // capitalize it.
-        result += input[i] + ('a' - 'A');
+        result += name[i] + ('a' - 'A');
       } else {
       } else {
         // Capital letters after the first are left as-is.
         // Capital letters after the first are left as-is.
-        result += input[i];
+        result += name[i];
       }
       }
       cap_first_letter = false;
       cap_first_letter = false;
-    } else if ('0' <= input[i] && input[i] <= '9') {
-      result += input[i];
+    } else if ('0' <= name[i] && name[i] <= '9') {
+      result += name[i];
       cap_first_letter = true;
       cap_first_letter = true;
     } else {
     } else {
       cap_first_letter = true;
       cap_first_letter = true;
     }
     }
   }
   }
   // Add a trailing "_" if the name should be altered.
   // Add a trailing "_" if the name should be altered.
-  if (input[input.size() - 1] == '#') {
+  if (name[name.size() - 1] == '#') {
     result += '_';
     result += '_';
   }
   }
   return result;
   return result;
 }
 }
 
 
-std::string EscapeDollor(const string& to_escape) {
-  return StringReplace(to_escape, "$", "\\$", true);
-}
-
-std::string BinaryToHex(const string& src) {
+std::string BinaryToHex(const string& binary) {
   string dest;
   string dest;
   size_t i;
   size_t i;
   unsigned char symbol[16] = {
   unsigned char symbol[16] = {
@@ -600,12 +595,12 @@ std::string BinaryToHex(const string& src) {
     'c', 'd', 'e', 'f',
     'c', 'd', 'e', 'f',
   };
   };
 
 
-  dest.resize(src.size() * 2);
+  dest.resize(binary.size() * 2);
   char* append_ptr = &dest[0];
   char* append_ptr = &dest[0];
 
 
-  for (i = 0; i < src.size(); i++) {
-    *append_ptr++ = symbol[(src[i] & 0xf0) >> 4];
-    *append_ptr++ = symbol[src[i] & 0x0f];
+  for (i = 0; i < binary.size(); i++) {
+    *append_ptr++ = symbol[(binary[i] & 0xf0) >> 4];
+    *append_ptr++ = symbol[binary[i] & 0x0f];
   }
   }
 
 
   return dest;
   return dest;
@@ -1103,7 +1098,7 @@ void LegacyGenerateClassFile(const FileDescriptor* file, const DescriptorType* d
   GenerateHead(file, &printer);
   GenerateHead(file, &printer);
 
 
   std::string php_namespace = RootPhpNamespace(desc, is_descriptor);
   std::string php_namespace = RootPhpNamespace(desc, is_descriptor);
-  if (php_namespace != "") {
+  if (!php_namespace.empty()) {
     printer.Print(
     printer.Print(
         "namespace ^name^;\n\n",
         "namespace ^name^;\n\n",
         "name", php_namespace);
         "name", php_namespace);