aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
diff options
context:
space:
mode:
authorGravatar Jon Skeet <skeet@pobox.com>2015-06-17 14:59:10 +0100
committerGravatar Jon Skeet <skeet@pobox.com>2015-06-17 14:59:10 +0100
commit828b7e61d0443832d99002fbda12a359e5f9f221 (patch)
tree1f271cdb345b968dba08947b9319ba7d738f3476 /src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
parentfb1547b3884ace3be6acf9e947686d627ff90179 (diff)
Use the fact that we know the tag size and bytes at codegen time to optimize.
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.cc8
1 files changed, 4 insertions, 4 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 4b570d3b..3553fe12 100644
--- a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
@@ -79,8 +79,8 @@ void RepeatedMessageFieldGenerator::GenerateParsingCode(io::Printer* printer) {
}
void RepeatedMessageFieldGenerator::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.
+ // 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"
@@ -89,13 +89,13 @@ void RepeatedMessageFieldGenerator::GenerateSerializationCode(io::Printer* print
}
void RepeatedMessageFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) {
- // TODO(jonskeet): Put this into CodedOutputStream.
printer->Print(
variables_,
"if ($name$_.Count > 0) {\n"
" foreach ($type_name$ element in $name$_) {\n"
- " size += pb::CodedOutputStream.ComputeMessageSize($number$, element);\n"
+ " size += pb::CodedOutputStream.ComputeMessageSize(element);\n"
" }\n"
+ " size += $tag_size$ * $name$_.Count;\n"
"}\n");
}