Sfoglia il codice sorgente

Keep loop bounds in a local variable.

Chris Kennelly 8 anni fa
parent
commit
a6c30d9705

+ 2 - 2
src/google/protobuf/compiler/cpp/cpp_enum_field.cc

@@ -436,7 +436,7 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) const {
       "}\n");
       "}\n");
   }
   }
   printer->Print(variables_,
   printer->Print(variables_,
-      "for (int i = 0; i < this->$name$_size(); i++) {\n");
+      "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n");
   if (descriptor_->is_packed()) {
   if (descriptor_->is_packed()) {
     printer->Print(variables_,
     printer->Print(variables_,
       "  ::google::protobuf::internal::WireFormatLite::WriteEnumNoTag(\n"
       "  ::google::protobuf::internal::WireFormatLite::WriteEnumNoTag(\n"
@@ -464,7 +464,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const {
       "}\n");
       "}\n");
   }
   }
   printer->Print(variables_,
   printer->Print(variables_,
-      "for (int i = 0; i < this->$name$_size(); i++) {\n");
+      "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n");
   if (descriptor_->is_packed()) {
   if (descriptor_->is_packed()) {
     printer->Print(variables_,
     printer->Print(variables_,
       "  target = ::google::protobuf::internal::WireFormatLite::WriteEnumNoTagToArray(\n"
       "  target = ::google::protobuf::internal::WireFormatLite::WriteEnumNoTagToArray(\n"

+ 2 - 2
src/google/protobuf/compiler/cpp/cpp_primitive_field.cc

@@ -394,7 +394,7 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) const {
   }
   }
   if (!array_written) {
   if (!array_written) {
     printer->Print(variables_,
     printer->Print(variables_,
-        "for (int i = 0; i < this->$name$_size(); i++) {\n");
+        "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n");
     if (descriptor_->is_packed()) {
     if (descriptor_->is_packed()) {
       printer->Print(variables_,
       printer->Print(variables_,
         "  ::google::protobuf::internal::WireFormatLite::Write$declared_type$NoTag(\n"
         "  ::google::protobuf::internal::WireFormatLite::Write$declared_type$NoTag(\n"
@@ -423,7 +423,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const {
       "}\n");
       "}\n");
   }
   }
   printer->Print(variables_,
   printer->Print(variables_,
-      "for (int i = 0; i < this->$name$_size(); i++) {\n");
+      "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n");
   if (descriptor_->is_packed()) {
   if (descriptor_->is_packed()) {
     printer->Print(variables_,
     printer->Print(variables_,
       "  target = ::google::protobuf::internal::WireFormatLite::\n"
       "  target = ::google::protobuf::internal::WireFormatLite::\n"

+ 10 - 10
src/google/protobuf/descriptor.pb.cc

@@ -1622,13 +1622,13 @@ void FileDescriptorProto::SerializeWithCachedSizes(
   }
   }
 
 
   // repeated int32 public_dependency = 10;
   // repeated int32 public_dependency = 10;
-  for (int i = 0; i < this->public_dependency_size(); i++) {
+  for (int i = 0, n = this->public_dependency_size(); i < n; i++) {
     ::google::protobuf::internal::WireFormatLite::WriteInt32(
     ::google::protobuf::internal::WireFormatLite::WriteInt32(
       10, this->public_dependency(i), output);
       10, this->public_dependency(i), output);
   }
   }
 
 
   // repeated int32 weak_dependency = 11;
   // repeated int32 weak_dependency = 11;
-  for (int i = 0; i < this->weak_dependency_size(); i++) {
+  for (int i = 0, n = this->weak_dependency_size(); i < n; i++) {
     ::google::protobuf::internal::WireFormatLite::WriteInt32(
     ::google::protobuf::internal::WireFormatLite::WriteInt32(
       11, this->weak_dependency(i), output);
       11, this->weak_dependency(i), output);
   }
   }
@@ -1729,13 +1729,13 @@ void FileDescriptorProto::SerializeWithCachedSizes(
   }
   }
 
 
   // repeated int32 public_dependency = 10;
   // repeated int32 public_dependency = 10;
-  for (int i = 0; i < this->public_dependency_size(); i++) {
+  for (int i = 0, n = this->public_dependency_size(); i < n; i++) {
     target = ::google::protobuf::internal::WireFormatLite::
     target = ::google::protobuf::internal::WireFormatLite::
       WriteInt32ToArray(10, this->public_dependency(i), target);
       WriteInt32ToArray(10, this->public_dependency(i), target);
   }
   }
 
 
   // repeated int32 weak_dependency = 11;
   // repeated int32 weak_dependency = 11;
-  for (int i = 0; i < this->weak_dependency_size(); i++) {
+  for (int i = 0, n = this->weak_dependency_size(); i < n; i++) {
     target = ::google::protobuf::internal::WireFormatLite::
     target = ::google::protobuf::internal::WireFormatLite::
       WriteInt32ToArray(11, this->weak_dependency(i), target);
       WriteInt32ToArray(11, this->weak_dependency(i), target);
   }
   }
@@ -14101,7 +14101,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes(
     ::google::protobuf::internal::WireFormatLite::WriteTag(1, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
     ::google::protobuf::internal::WireFormatLite::WriteTag(1, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
     output->WriteVarint32(_path_cached_byte_size_);
     output->WriteVarint32(_path_cached_byte_size_);
   }
   }
-  for (int i = 0; i < this->path_size(); i++) {
+  for (int i = 0, n = this->path_size(); i < n; i++) {
     ::google::protobuf::internal::WireFormatLite::WriteInt32NoTag(
     ::google::protobuf::internal::WireFormatLite::WriteInt32NoTag(
       this->path(i), output);
       this->path(i), output);
   }
   }
@@ -14111,7 +14111,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes(
     ::google::protobuf::internal::WireFormatLite::WriteTag(2, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
     ::google::protobuf::internal::WireFormatLite::WriteTag(2, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
     output->WriteVarint32(_span_cached_byte_size_);
     output->WriteVarint32(_span_cached_byte_size_);
   }
   }
-  for (int i = 0; i < this->span_size(); i++) {
+  for (int i = 0, n = this->span_size(); i < n; i++) {
     ::google::protobuf::internal::WireFormatLite::WriteInt32NoTag(
     ::google::protobuf::internal::WireFormatLite::WriteInt32NoTag(
       this->span(i), output);
       this->span(i), output);
   }
   }
@@ -14166,7 +14166,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes(
     target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray(
     target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray(
       _path_cached_byte_size_, target);
       _path_cached_byte_size_, target);
   }
   }
-  for (int i = 0; i < this->path_size(); i++) {
+  for (int i = 0, n = this->path_size(); i < n; i++) {
     target = ::google::protobuf::internal::WireFormatLite::
     target = ::google::protobuf::internal::WireFormatLite::
       WriteInt32NoTagToArray(this->path(i), target);
       WriteInt32NoTagToArray(this->path(i), target);
   }
   }
@@ -14180,7 +14180,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes(
     target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray(
     target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray(
       _span_cached_byte_size_, target);
       _span_cached_byte_size_, target);
   }
   }
-  for (int i = 0; i < this->span_size(); i++) {
+  for (int i = 0, n = this->span_size(); i < n; i++) {
     target = ::google::protobuf::internal::WireFormatLite::
     target = ::google::protobuf::internal::WireFormatLite::
       WriteInt32NoTagToArray(this->span(i), target);
       WriteInt32NoTagToArray(this->span(i), target);
   }
   }
@@ -15078,7 +15078,7 @@ void GeneratedCodeInfo_Annotation::SerializeWithCachedSizes(
     ::google::protobuf::internal::WireFormatLite::WriteTag(1, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
     ::google::protobuf::internal::WireFormatLite::WriteTag(1, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
     output->WriteVarint32(_path_cached_byte_size_);
     output->WriteVarint32(_path_cached_byte_size_);
   }
   }
-  for (int i = 0; i < this->path_size(); i++) {
+  for (int i = 0, n = this->path_size(); i < n; i++) {
     ::google::protobuf::internal::WireFormatLite::WriteInt32NoTag(
     ::google::protobuf::internal::WireFormatLite::WriteInt32NoTag(
       this->path(i), output);
       this->path(i), output);
   }
   }
@@ -15123,7 +15123,7 @@ void GeneratedCodeInfo_Annotation::SerializeWithCachedSizes(
     target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray(
     target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray(
       _path_cached_byte_size_, target);
       _path_cached_byte_size_, target);
   }
   }
-  for (int i = 0; i < this->path_size(); i++) {
+  for (int i = 0, n = this->path_size(); i < n; i++) {
     target = ::google::protobuf::internal::WireFormatLite::
     target = ::google::protobuf::internal::WireFormatLite::
       WriteInt32NoTagToArray(this->path(i), target);
       WriteInt32NoTagToArray(this->path(i), target);
   }
   }