Commit 8e465dcf authored by Feng Xiao's avatar Feng Xiao Committed by GitHub

Merge pull request #2810 from xfxyjwf/i1994

Avoid redundant type casts for oneof bytes fields.
parents af2d5f5a c3115431
...@@ -523,8 +523,17 @@ void ImmutablePrimitiveOneofFieldGenerator:: ...@@ -523,8 +523,17 @@ void ImmutablePrimitiveOneofFieldGenerator::
GenerateSerializationCode(io::Printer* printer) const { GenerateSerializationCode(io::Printer* printer) const {
printer->Print(variables_, printer->Print(variables_,
"if ($has_oneof_case_message$) {\n" "if ($has_oneof_case_message$) {\n"
" output.write$capitalized_type$(\n" " output.write$capitalized_type$(\n");
" $number$, ($type$)(($boxed_type$) $oneof_name$_));\n" // $type$ and $boxed_type$ is the same for bytes fields so we don't need to
// do redundant casts.
if (GetJavaType(descriptor_) == JAVATYPE_BYTES) {
printer->Print(variables_,
" $number$, ($type$) $oneof_name$_);\n");
} else {
printer->Print(variables_,
" $number$, ($type$)(($boxed_type$) $oneof_name$_));\n");
}
printer->Print(
"}\n"); "}\n");
} }
...@@ -533,8 +542,17 @@ GenerateSerializedSizeCode(io::Printer* printer) const { ...@@ -533,8 +542,17 @@ GenerateSerializedSizeCode(io::Printer* printer) const {
printer->Print(variables_, printer->Print(variables_,
"if ($has_oneof_case_message$) {\n" "if ($has_oneof_case_message$) {\n"
" size += com.google.protobuf.CodedOutputStream\n" " size += com.google.protobuf.CodedOutputStream\n"
" .compute$capitalized_type$Size(\n" " .compute$capitalized_type$Size(\n");
" $number$, ($type$)(($boxed_type$) $oneof_name$_));\n" // $type$ and $boxed_type$ is the same for bytes fields so we don't need to
// do redundant casts.
if (GetJavaType(descriptor_) == JAVATYPE_BYTES) {
printer->Print(variables_,
" $number$, ($type$) $oneof_name$_);\n");
} else {
printer->Print(variables_,
" $number$, ($type$)(($boxed_type$) $oneof_name$_));\n");
}
printer->Print(
"}\n"); "}\n");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment