Unverified Commit 8af87de9 authored by Feng Xiao's avatar Feng Xiao Committed by GitHub

Merge pull request #2121 from mazurkin/issue-2108

issue-2108 [protoc/Java] Excessive copying on buildPartial()
parents e264d6bc aba6f7ef
...@@ -305,11 +305,15 @@ GenerateBuildingCode(io::Printer* printer) const { ...@@ -305,11 +305,15 @@ GenerateBuildingCode(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) { if (SupportFieldPresence(descriptor_->file())) {
printer->Print(variables_, printer->Print(variables_,
"if ($get_has_field_bit_from_local$) {\n" "if ($get_has_field_bit_from_local$) {\n"
" result.$name$_ = $name$_;\n"
" $set_has_field_bit_to_local$;\n" " $set_has_field_bit_to_local$;\n"
"} else {\n"
" result.$name$_ = $default_number$;\n"
"}\n"); "}\n");
} else {
printer->Print(variables_,
"result.$name$_ = $name$_;\n");
} }
printer->Print(variables_,
"result.$name$_ = $name$_;\n");
} }
void ImmutableEnumFieldGenerator:: void ImmutableEnumFieldGenerator::
......
...@@ -233,12 +233,9 @@ void ImmutableLazyMessageFieldGenerator:: ...@@ -233,12 +233,9 @@ void ImmutableLazyMessageFieldGenerator::
GenerateBuildingCode(io::Printer* printer) const { GenerateBuildingCode(io::Printer* printer) const {
printer->Print(variables_, printer->Print(variables_,
"if ($get_has_field_bit_from_local$) {\n" "if ($get_has_field_bit_from_local$) {\n"
" result.$name$_.set($name$_);\n"
" $set_has_field_bit_to_local$;\n" " $set_has_field_bit_to_local$;\n"
"}\n"); "}\n");
printer->Print(variables_,
"result.$name$_.set(\n"
" $name$_);\n");
} }
void ImmutableLazyMessageFieldGenerator:: void ImmutableLazyMessageFieldGenerator::
......
...@@ -255,7 +255,7 @@ GenerateBuilderMembers(io::Printer* printer) const { ...@@ -255,7 +255,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
bool support_field_presence = SupportFieldPresence(descriptor_->file()); bool support_field_presence = SupportFieldPresence(descriptor_->file());
printer->Print(variables_, printer->Print(variables_,
"private $type$ $name$_ = null;\n"); "private $type$ $name$_;\n");
printer->Print(variables_, printer->Print(variables_,
// If this builder is non-null, it is used and the other fields are // If this builder is non-null, it is used and the other fields are
...@@ -444,15 +444,20 @@ void ImmutableMessageFieldGenerator:: ...@@ -444,15 +444,20 @@ void ImmutableMessageFieldGenerator::
GenerateBuildingCode(io::Printer* printer) const { GenerateBuildingCode(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) { if (SupportFieldPresence(descriptor_->file())) {
printer->Print(variables_, printer->Print(variables_,
"if ($get_has_field_bit_from_local$) {\n" "if ($get_has_field_bit_from_local$) {\n");
" $set_has_field_bit_to_local$;\n" printer->Indent();
"}\n"); PrintNestedBuilderCondition(printer,
"result.$name$_ = $name$_;\n",
"result.$name$_ = $name$Builder_.build();\n");
printer->Outdent();
printer->Print(variables_,
" $set_has_field_bit_to_local$;\n"
"}\n");
} else {
PrintNestedBuilderCondition(printer,
"result.$name$_ = $name$_;\n",
"result.$name$_ = $name$Builder_.build();\n");
} }
PrintNestedBuilderCondition(printer,
"result.$name$_ = $name$_;\n",
"result.$name$_ = $name$Builder_.build();\n");
} }
void ImmutableMessageFieldGenerator:: void ImmutableMessageFieldGenerator::
......
...@@ -264,7 +264,9 @@ GenerateFieldBuilderInitializationCode(io::Printer* printer) const { ...@@ -264,7 +264,9 @@ GenerateFieldBuilderInitializationCode(io::Printer* printer) const {
void ImmutablePrimitiveFieldGenerator:: void ImmutablePrimitiveFieldGenerator::
GenerateInitializationCode(io::Printer* printer) const { GenerateInitializationCode(io::Printer* printer) const {
printer->Print(variables_, "$name$_ = $default$;\n"); if (!IsDefaultValueJavaDefault(descriptor_)) {
printer->Print(variables_, "$name$_ = $default$;\n");
}
} }
void ImmutablePrimitiveFieldGenerator:: void ImmutablePrimitiveFieldGenerator::
...@@ -294,11 +296,21 @@ GenerateBuildingCode(io::Printer* printer) const { ...@@ -294,11 +296,21 @@ GenerateBuildingCode(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) { if (SupportFieldPresence(descriptor_->file())) {
printer->Print(variables_, printer->Print(variables_,
"if ($get_has_field_bit_from_local$) {\n" "if ($get_has_field_bit_from_local$) {\n"
" $set_has_field_bit_to_local$;\n" " result.$name$_ = $name$_;\n"
"}\n"); " $set_has_field_bit_to_local$;\n");
if (IsDefaultValueJavaDefault(descriptor_)) {
printer->Print(variables_,
"}\n");
} else {
printer->Print(variables_,
"} else {\n"
" result.$name$_ = $default$;\n"
"}\n");
}
} else {
printer->Print(variables_,
"result.$name$_ = $name$_;\n");
} }
printer->Print(variables_,
"result.$name$_ = $name$_;\n");
} }
void ImmutablePrimitiveFieldGenerator:: void ImmutablePrimitiveFieldGenerator::
......
...@@ -405,11 +405,15 @@ GenerateBuildingCode(io::Printer* printer) const { ...@@ -405,11 +405,15 @@ GenerateBuildingCode(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) { if (SupportFieldPresence(descriptor_->file())) {
printer->Print(variables_, printer->Print(variables_,
"if ($get_has_field_bit_from_local$) {\n" "if ($get_has_field_bit_from_local$) {\n"
" result.$name$_ = $name$_;\n"
" $set_has_field_bit_to_local$;\n" " $set_has_field_bit_to_local$;\n"
"} else {\n"
" result.$name$_ = $default$;\n"
"}\n"); "}\n");
} else {
printer->Print(variables_,
"result.$name$_ = $name$_;\n");
} }
printer->Print(variables_,
"result.$name$_ = $name$_;\n");
} }
void ImmutableStringFieldGenerator:: void ImmutableStringFieldGenerator::
......
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