Protobuf: changed all for-loops in generated code into while-loops
This commit is contained in:
Binary file not shown.
+10
-5
@@ -133,16 +133,18 @@ void FieldGenerator::generateSerializationForPacked(io::Printer *printer, bool i
|
|||||||
printer->Print(vars, "output.writeInt32NoTag(arrayByteSize)\n");
|
printer->Print(vars, "output.writeInt32NoTag(arrayByteSize)\n");
|
||||||
|
|
||||||
// all elements
|
// all elements
|
||||||
printer->Print(vars, "for (item in $fieldName$) {\n");
|
printer->Print("var i = 0\n");
|
||||||
|
printer->Print(vars, "while (i < $fieldName$.size) {\n");
|
||||||
printer->Indent();
|
printer->Indent();
|
||||||
|
|
||||||
// hack: see above
|
// hack: similar to one above
|
||||||
FieldGenerator singleFieldGen = FieldGenerator(descriptor, enclosingClass, nameResolver);
|
FieldGenerator singleFieldGen = FieldGenerator(descriptor, enclosingClass, nameResolver);
|
||||||
singleFieldGen.simpleName = "item";
|
singleFieldGen.simpleName = simpleName + "[i]";
|
||||||
singleFieldGen.protoLabel = FieldDescriptor::LABEL_OPTIONAL;
|
singleFieldGen.protoLabel = FieldDescriptor::LABEL_OPTIONAL;
|
||||||
|
|
||||||
singleFieldGen.generateSerializationCode(printer, isRead, /* noTag = */ isPrimitive, /* isField = */ false);
|
singleFieldGen.generateSerializationCode(printer, isRead, /* noTag = */ isPrimitive, /* isField = */ false);
|
||||||
|
|
||||||
|
printer->Print(vars, "i += 1\n");
|
||||||
printer->Outdent(); // for-loop
|
printer->Outdent(); // for-loop
|
||||||
printer->Print("}\n");
|
printer->Print("}\n");
|
||||||
}
|
}
|
||||||
@@ -363,15 +365,18 @@ void FieldGenerator::generateSizeEstimationCode(io::Printer *printer, string var
|
|||||||
printer->Print("var arraySize = 0\n");
|
printer->Print("var arraySize = 0\n");
|
||||||
|
|
||||||
// iterate over all elements of array
|
// iterate over all elements of array
|
||||||
printer->Print(vars, "for (item in $fieldName$) {\n");
|
printer->Print("var i = 0\n");
|
||||||
|
printer->Print(vars, "while (i < $fieldName$.size) {\n");
|
||||||
printer->Indent();
|
printer->Indent();
|
||||||
|
|
||||||
// hack: reuse generateSizeEstimationCode in the same manner as in generateSerializationCode
|
// hack: reuse generateSizeEstimationCode in the same manner as in generateSerializationCode
|
||||||
FieldGenerator singleFieldGen = FieldGenerator(descriptor, enclosingClass, nameResolver);
|
FieldGenerator singleFieldGen = FieldGenerator(descriptor, enclosingClass, nameResolver);
|
||||||
singleFieldGen.protoLabel = FieldDescriptor::LABEL_OPTIONAL;
|
singleFieldGen.protoLabel = FieldDescriptor::LABEL_OPTIONAL;
|
||||||
singleFieldGen.simpleName = "item";
|
singleFieldGen.simpleName = simpleName + "[i]";
|
||||||
singleFieldGen.generateSizeEstimationCode(printer, "arraySize", noTag, /* isField = */ false);
|
singleFieldGen.generateSizeEstimationCode(printer, "arraySize", noTag, /* isField = */ false);
|
||||||
|
|
||||||
|
printer->Print(vars, "i += 1\n");
|
||||||
|
|
||||||
printer->Outdent(); // for-loop
|
printer->Outdent(); // for-loop
|
||||||
printer->Print("}\n");
|
printer->Print("}\n");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user