diff options
author | 2017-01-31 12:27:32 -0800 | |
---|---|---|
committer | 2017-02-15 11:41:46 -0800 | |
commit | 8af35f28f696b5fa70ec7cfb64111f87b45d55b7 (patch) | |
tree | 5033fde1e05faf51ef753d304a91f753c8530e69 /src/google/protobuf/compiler | |
parent | a6c30d97054bbd6d591e471da112c5dfef501bb4 (diff) |
Keep loop bounds in a local variable for string fields.
Diffstat (limited to 'src/google/protobuf/compiler')
-rw-r--r-- | src/google/protobuf/compiler/cpp/cpp_string_field.cc | 6 | ||||
-rw-r--r-- | src/google/protobuf/compiler/plugin.pb.cc | 6 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.cc b/src/google/protobuf/compiler/cpp/cpp_string_field.cc index 9c4a117b..664a2779 100644 --- a/src/google/protobuf/compiler/cpp/cpp_string_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_string_field.cc @@ -969,7 +969,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) const { void RepeatedStringFieldGenerator:: GenerateSerializeWithCachedSizes(io::Printer* printer) const { 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"); printer->Indent(); if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { GenerateUtf8CheckCodeForString( @@ -986,7 +986,7 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) const { void RepeatedStringFieldGenerator:: GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { 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"); printer->Indent(); if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { GenerateUtf8CheckCodeForString( @@ -1005,7 +1005,7 @@ GenerateByteSize(io::Printer* printer) const { printer->Print(variables_, "total_size += $tag_size$ *\n" " ::google::protobuf::internal::FromIntSize(this->$name$_size());\n" - "for (int i = 0; i < this->$name$_size(); i++) {\n" + "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n" " total_size += ::google::protobuf::internal::WireFormatLite::$declared_type$Size(\n" " this->$name$(i));\n" "}\n"); diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index f806392a..686ee477 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -887,7 +887,7 @@ void CodeGeneratorRequest::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.compiler.CodeGeneratorRequest) // repeated string file_to_generate = 1; - for (int i = 0; i < this->file_to_generate_size(); i++) { + for (int i = 0, n = this->file_to_generate_size(); i < n; i++) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->file_to_generate(i).data(), this->file_to_generate(i).length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -930,7 +930,7 @@ void CodeGeneratorRequest::SerializeWithCachedSizes( (void)deterministic; // Unused // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.CodeGeneratorRequest) // repeated string file_to_generate = 1; - for (int i = 0; i < this->file_to_generate_size(); i++) { + for (int i = 0, n = this->file_to_generate_size(); i < n; i++) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->file_to_generate(i).data(), this->file_to_generate(i).length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -984,7 +984,7 @@ size_t CodeGeneratorRequest::ByteSizeLong() const { // repeated string file_to_generate = 1; total_size += 1 * ::google::protobuf::internal::FromIntSize(this->file_to_generate_size()); - for (int i = 0; i < this->file_to_generate_size(); i++) { + for (int i = 0, n = this->file_to_generate_size(); i < n; i++) { total_size += ::google::protobuf::internal::WireFormatLite::StringSize( this->file_to_generate(i)); } |