aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/cpp/cpp_string_field.cc
diff options
context:
space:
mode:
authorGravatar Chris Kennelly <ckennelly@google.com>2017-01-31 12:27:32 -0800
committerGravatar Chris Kennelly <ckennelly@google.com>2017-02-15 11:41:46 -0800
commit8af35f28f696b5fa70ec7cfb64111f87b45d55b7 (patch)
tree5033fde1e05faf51ef753d304a91f753c8530e69 /src/google/protobuf/compiler/cpp/cpp_string_field.cc
parenta6c30d97054bbd6d591e471da112c5dfef501bb4 (diff)
Keep loop bounds in a local variable for string fields.
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_string_field.cc')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_string_field.cc6
1 files changed, 3 insertions, 3 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");