aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/csharp/csharp_field_base.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_field_base.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_field_base.cc')
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_field_base.cc15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/src/google/protobuf/compiler/csharp/csharp_field_base.cc
index ec0d51ca..54f281ee 100644
--- a/src/google/protobuf/compiler/csharp/csharp_field_base.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_field_base.cc
@@ -35,6 +35,7 @@
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
+#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/stubs/strutil.h>
@@ -55,8 +56,18 @@ void FieldGeneratorBase::SetCommonFieldVariables(
// Note: this will be valid even though the tag emitted for packed and unpacked versions of
// repeated fields varies by wire format. The wire format is encoded in the bottom 3 bits, which
// never effects the tag size.
- int tagSize = internal::WireFormat::TagSize(descriptor_->number(), descriptor_->type());
- (*variables)["tag_size"] = SimpleItoa(tagSize);
+ int tag_size = internal::WireFormat::TagSize(descriptor_->number(), descriptor_->type());
+ uint tag = internal::WireFormat::MakeTag(descriptor_);
+ uint8 tag_array[5];
+ io::CodedOutputStream::WriteTagToArray(tag, tag_array);
+ string tag_bytes = SimpleItoa(tag_array[0]);
+ for (int i = 1; i < tag_size; i++) {
+ tag_bytes += ", " + SimpleItoa(tag_array[i]);
+ }
+
+ (*variables)["tag_size"] = SimpleItoa(tag_size);
+ (*variables)["tag_bytes"] = tag_bytes;
+
(*variables)["property_name"] = property_name();
(*variables)["type_name"] = type_name();
(*variables)["name"] = name();