Move Count checks into the serialization code

I wouldn't expect this to affect anything, but it appears to.
pull/515/head
Jon Skeet 10 years ago
parent 5685e98711
commit 5a33827eec
  1. 6
      src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
  2. 4
      src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
  3. 15
      src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc

@ -80,11 +80,11 @@ void RepeatedEnumFieldGenerator::GenerateParsingCode(io::Printer* printer) {
}
void RepeatedEnumFieldGenerator::GenerateSerializationCode(io::Printer* printer) {
// TODO(jonskeet): Originally, this checked for Count > 0 first.
// The Write* call should make that cheap though - no need to generate it every time.
printer->Print(
variables_,
"output.Write$packed$EnumArray($number$, $name$_);\n");
"if ($name$_.Count > 0) {\n"
" output.Write$packed$EnumArray($number$, $name$_);\n"
"}\n");
}
void RepeatedEnumFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) {

@ -83,7 +83,9 @@ void RepeatedMessageFieldGenerator::GenerateSerializationCode(io::Printer* print
// The Write* call should make that cheap though - no need to generate it every time.
printer->Print(
variables_,
"output.WriteMessageArray($number$, $name$_);\n");
"if ($name$_.Count > 0) {\n"
" output.WriteMessageArray($number$, $name$_);\n"
"}\n");
}
void RepeatedMessageFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) {

@ -49,6 +49,7 @@ namespace csharp {
RepeatedPrimitiveFieldGenerator::RepeatedPrimitiveFieldGenerator(
const FieldDescriptor* descriptor, int fieldOrdinal)
: FieldGeneratorBase(descriptor, fieldOrdinal) {
variables_["packed"] = descriptor->is_packed() ? "Packed" : "";
}
RepeatedPrimitiveFieldGenerator::~RepeatedPrimitiveFieldGenerator() {
@ -79,15 +80,11 @@ void RepeatedPrimitiveFieldGenerator::GenerateParsingCode(io::Printer* printer)
void RepeatedPrimitiveFieldGenerator::GenerateSerializationCode(
io::Printer* printer) {
// TODO(jonskeet): Originally, this checked for Count > 0 first.
// The Write* call should make that cheap though - no need to generate it every time.
if (descriptor_->is_packed()) {
printer->Print(variables_,
"output.WritePacked$capitalized_type_name$Array($number$, $name$_);\n");
} else {
printer->Print(variables_,
"output.Write$capitalized_type_name$Array($number$, $name$_);\n");
}
printer->Print(
variables_,
"if ($name$_.Count > 0) {\n"
" output.Write$packed$$capitalized_type_name$Array($number$, $name$_);\n"
"}\n");
}
void RepeatedPrimitiveFieldGenerator::GenerateSerializedSizeCode(

Loading…
Cancel
Save