| Index: third_party/protobuf/src/google/protobuf/compiler/java/java_string_field_lite.cc
|
| diff --git a/third_party/protobuf/src/google/protobuf/compiler/java/java_string_field_lite.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_string_field_lite.cc
|
| index eb5964bd300e0ccef72611b2c0915c170a236f67..0b92c021852d83606a9206cf09f4bb94fd26f7ae 100644
|
| --- a/third_party/protobuf/src/google/protobuf/compiler/java/java_string_field_lite.cc
|
| +++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_string_field_lite.cc
|
| @@ -84,8 +84,6 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
|
| // by the proto compiler
|
| (*variables)["deprecation"] = descriptor->options().deprecated()
|
| ? "@java.lang.Deprecated " : "";
|
| - (*variables)["on_changed"] =
|
| - HasDescriptorMethods(descriptor->containing_type()) ? "onChanged();" : "";
|
|
|
| if (SupportFieldPresence(descriptor->file())) {
|
| // For singular messages and builders, one bit is used for the hasField bit.
|
| @@ -103,7 +101,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
|
| (*variables)["clear_has_field_bit_message"] = "";
|
|
|
| (*variables)["is_field_present_message"] =
|
| - "!get" + (*variables)["capitalized_name"] + ".isEmpty()";
|
| + "!" + (*variables)["name"] + "_.isEmpty()";
|
| }
|
|
|
| // For repeated builders, the underlying list tracks mutability state.
|
| @@ -301,22 +299,16 @@ GenerateInitializationCode(io::Printer* printer) const {
|
| }
|
|
|
| void ImmutableStringFieldLiteGenerator::
|
| -GenerateMergingCode(io::Printer* printer) const {
|
| +GenerateVisitCode(io::Printer* printer) const {
|
| if (SupportFieldPresence(descriptor_->file())) {
|
| - // Allow a slight breach of abstraction here in order to avoid forcing
|
| - // all string fields to Strings when copying fields from a Message.
|
| printer->Print(variables_,
|
| - "if (other.has$capitalized_name$()) {\n"
|
| - " $set_has_field_bit_message$\n"
|
| - " $name$_ = other.$name$_;\n"
|
| - " $on_changed$\n"
|
| - "}\n");
|
| + "$name$_ = visitor.visitString(\n"
|
| + " has$capitalized_name$(), $name$_,\n"
|
| + " other.has$capitalized_name$(), other.$name$_);\n");
|
| } else {
|
| printer->Print(variables_,
|
| - "if (!other.get$capitalized_name$().isEmpty()) {\n"
|
| - " $name$_ = other.$name$_;\n"
|
| - " $on_changed$\n"
|
| - "}\n");
|
| + "$name$_ = visitor.visitString(!$name$_.isEmpty(), $name$_,\n"
|
| + " !other.$name$_.isEmpty(), other.$name$_);\n");
|
| }
|
| }
|
|
|
| @@ -523,13 +515,10 @@ GenerateBuilderMembers(io::Printer* printer) const {
|
| }
|
|
|
| void ImmutableStringOneofFieldLiteGenerator::
|
| -GenerateMergingCode(io::Printer* printer) const {
|
| - // Allow a slight breach of abstraction here in order to avoid forcing
|
| - // all string fields to Strings when copying fields from a Message.
|
| +GenerateVisitCode(io::Printer* printer) const {
|
| printer->Print(variables_,
|
| - "$set_oneof_case_message$;\n"
|
| - "$oneof_name$_ = other.$oneof_name$_;\n"
|
| - "$on_changed$\n");
|
| + "$oneof_name$_ = visitor.visitOneofString(\n"
|
| + " $has_oneof_case_message$, $oneof_name$_, other.$oneof_name$_);\n");
|
| }
|
|
|
| void ImmutableStringOneofFieldLiteGenerator::
|
| @@ -650,8 +639,8 @@ GenerateMembers(io::Printer* printer) const {
|
| printer->Print(variables_,
|
| "private void ensure$capitalized_name$IsMutable() {\n"
|
| " if (!$is_mutable$) {\n"
|
| - " $name$_ = com.google.protobuf.GeneratedMessageLite.newProtobufList(\n"
|
| - " $name$_);\n"
|
| + " $name$_ =\n"
|
| + " com.google.protobuf.GeneratedMessageLite.mutableCopy($name$_);\n"
|
| " }\n"
|
| "}\n");
|
|
|
| @@ -778,22 +767,9 @@ GenerateInitializationCode(io::Printer* printer) const {
|
| }
|
|
|
| void RepeatedImmutableStringFieldLiteGenerator::
|
| -GenerateMergingCode(io::Printer* printer) const {
|
| - // The code below does two optimizations:
|
| - // 1. If the other list is empty, there's nothing to do. This ensures we
|
| - // don't allocate a new array if we already have an immutable one.
|
| - // 2. If the other list is non-empty and our current list is empty, we can
|
| - // reuse the other list which is guaranteed to be immutable.
|
| - printer->Print(variables_,
|
| - "if (!other.$name$_.isEmpty()) {\n"
|
| - " if ($name$_.isEmpty()) {\n"
|
| - " $name$_ = other.$name$_;\n"
|
| - " } else {\n"
|
| - " ensure$capitalized_name$IsMutable();\n"
|
| - " $name$_.addAll(other.$name$_);\n"
|
| - " }\n"
|
| - " $on_changed$\n"
|
| - "}\n");
|
| +GenerateVisitCode(io::Printer* printer) const {
|
| + printer->Print(variables_,
|
| + "$name$_= visitor.visitList($name$_, other.$name$_);\n");
|
| }
|
|
|
| void RepeatedImmutableStringFieldLiteGenerator::
|
| @@ -817,15 +793,11 @@ GenerateParsingCode(io::Printer* printer) const {
|
| }
|
| printer->Print(variables_,
|
| "if (!$is_mutable$) {\n"
|
| - " $name$_ = com.google.protobuf.GeneratedMessageLite.newProtobufList();\n"
|
| + " $name$_ =\n"
|
| + " com.google.protobuf.GeneratedMessageLite.mutableCopy($name$_);\n"
|
| "}\n");
|
| - if (CheckUtf8(descriptor_) || !HasDescriptorMethods(descriptor_->file())) {
|
| - printer->Print(variables_,
|
| - "$name$_.add(s);\n");
|
| - } else {
|
| - printer->Print(variables_,
|
| - "$name$_.add(bs);\n");
|
| - }
|
| + printer->Print(variables_,
|
| + "$name$_.add(s);\n");
|
| }
|
|
|
| void RepeatedImmutableStringFieldLiteGenerator::
|
|
|