aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/cpp
diff options
context:
space:
mode:
authorGravatar Chris Kennelly <ckennelly@google.com>2017-01-24 17:37:33 -0800
committerGravatar Chris Kennelly <ckennelly@google.com>2017-02-15 11:39:39 -0800
commit9db5b11c9cf2922435b53495b9c1e114525f0428 (patch)
treebe2e4da2021e6d25558ec2595f615724d9839781 /src/google/protobuf/compiler/cpp
parent0026dff9f6e7fbea541fd293cbf8ebcd254e374d (diff)
Work with truncated tag numbers.
This allows more compact comparisons (1 byte instead of 4 byte immediates on x86) for each possible wire/tag inside each field.
Diffstat (limited to 'src/google/protobuf/compiler/cpp')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_message.cc9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc
index 32f05f25..b4f1adfd 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_message.cc
@@ -3028,7 +3028,8 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
const FieldGenerator& field_generator = field_generators_.get(field);
// Emit code to parse the common, expected case.
- printer->Print("if (tag == $commontag$u) {\n",
+ printer->Print("if (static_cast<::google::protobuf::uint8>(tag) ==\n"
+ " static_cast<::google::protobuf::uint8>($commontag$u)) {\n",
"commontag", SimpleItoa(WireFormat::MakeTag(field)));
if (loops) {
@@ -3047,7 +3048,8 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
if (field->is_packed()) {
internal::WireFormatLite::WireType wiretype =
WireFormat::WireTypeForFieldType(field->type());
- printer->Print("} else if (tag == $uncommontag$u) {\n",
+ printer->Print("} else if (static_cast<::google::protobuf::uint8>(tag) ==\n"
+ " static_cast<::google::protobuf::uint8>($uncommontag$u)) {\n",
"uncommontag", SimpleItoa(
internal::WireFormatLite::MakeTag(
field->number(), wiretype)));
@@ -3057,7 +3059,8 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
} else if (field->is_packable() && !field->is_packed()) {
internal::WireFormatLite::WireType wiretype =
internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED;
- printer->Print("} else if (tag == $uncommontag$u) {\n",
+ printer->Print("} else if (static_cast<::google::protobuf::uint8>(tag) ==\n"
+ " static_cast<::google::protobuf::uint8>($uncommontag$u)) {\n",
"uncommontag", SimpleItoa(
internal::WireFormatLite::MakeTag(
field->number(), wiretype)));