aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
diff options
context:
space:
mode:
authorGravatar Jon Skeet <jonskeet@google.com>2015-06-26 17:37:14 +0100
committerGravatar Jon Skeet <jonskeet@google.com>2015-06-30 13:20:30 +0100
commitf2a27cc2c71b4dae3ff230574a73c1de88dd61b7 (patch)
tree58cdbbbd9262732c9a104171f2563f0f2da85acb /src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
parent241e17ba78b71a7ecccb289914ecaeab203b2373 (diff)
First pass (not yet compiling) at removing all the array handling code from Coded*Stream.
Prod code works, but some tests are broken. Obviously those need fixing, then more tests, and review benchmarks.
Diffstat (limited to 'src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc')
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
index 400f0e4f..c74e5d0d 100644
--- a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
@@ -57,6 +57,10 @@ RepeatedMessageFieldGenerator::~RepeatedMessageFieldGenerator() {
void RepeatedMessageFieldGenerator::GenerateMembers(io::Printer* printer) {
printer->Print(
variables_,
+ "private static readonly pb::FieldCodec<$type_name$> _repeated_$name$_codec\n"
+ " = pb::FieldCodec.ForMessage($tag$, $type_name$.Parser);\n");
+ printer->Print(
+ variables_,
"private readonly pbc::RepeatedField<$type_name$> $name$_ = new pbc::RepeatedField<$type_name$>();\n");
AddDeprecatedFlag(printer);
printer->Print(
@@ -75,28 +79,19 @@ void RepeatedMessageFieldGenerator::GenerateMergingCode(io::Printer* printer) {
void RepeatedMessageFieldGenerator::GenerateParsingCode(io::Printer* printer) {
printer->Print(
variables_,
- "input.ReadMessageArray($name$_, $type_name$.Parser);\n");
+ "$name$_.AddEntriesFrom(input, _repeated_$name$_codec);\n");
}
void RepeatedMessageFieldGenerator::GenerateSerializationCode(io::Printer* printer) {
- // TODO(jonskeet): Bake the foreach loop into the generated code? We lose the
- // advantage of knowing the tag bytes this way :(
printer->Print(
variables_,
- "if ($name$_.Count > 0) {\n"
- " output.WriteMessageArray($number$, $name$_);\n"
- "}\n");
+ "$name$_.WriteTo(output, _repeated_$name$_codec);\n");
}
void RepeatedMessageFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) {
printer->Print(
variables_,
- "if ($name$_.Count > 0) {\n"
- " foreach ($type_name$ element in $name$_) {\n"
- " size += pb::CodedOutputStream.ComputeMessageSize(element);\n"
- " }\n"
- " size += $tag_size$ * $name$_.Count;\n"
- "}\n");
+ "size += $name$_.CalculateSize(_repeated_$name$_codec);\n");
}
void RepeatedMessageFieldGenerator::WriteHash(io::Printer* printer) {