Merge pull request #6051 from haon4/201904171256

Down Integration to GitHub
pull/6056/head
Hao Nguyen 6 years ago committed by GitHub
commit 60b66a119d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      java/core/src/main/java/com/google/protobuf/Internal.java
  2. 25
      python/google/protobuf/pyext/message.cc
  3. 1
      src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc
  4. 4
      src/google/protobuf/compiler/cpp/cpp_field.cc
  5. 1
      src/google/protobuf/compiler/cpp/cpp_field.h
  6. 14
      src/google/protobuf/compiler/cpp/cpp_helpers.cc
  7. 25
      src/google/protobuf/compiler/cpp/cpp_message.cc
  8. 7
      src/google/protobuf/compiler/cpp/cpp_message.h
  9. 1
      src/google/protobuf/compiler/cpp/cpp_message_field.cc
  10. 8
      src/google/protobuf/compiler/cpp/cpp_service.cc
  11. 4
      src/google/protobuf/compiler/cpp/cpp_service.h
  12. 11
      src/google/protobuf/compiler/java/java_enum_field.cc
  13. 6
      src/google/protobuf/compiler/java/java_enum_field.h
  14. 55
      src/google/protobuf/compiler/java/java_enum_field_lite.cc
  15. 4
      src/google/protobuf/compiler/java/java_enum_field_lite.h
  16. 12
      src/google/protobuf/compiler/java/java_enum_lite.cc
  17. 2
      src/google/protobuf/compiler/java/java_enum_lite.h
  18. 4
      src/google/protobuf/compiler/java/java_extension.cc
  19. 1
      src/google/protobuf/compiler/java/java_extension.h
  20. 4
      src/google/protobuf/compiler/java/java_extension_lite.cc
  21. 1
      src/google/protobuf/compiler/java/java_extension_lite.h
  22. 2
      src/google/protobuf/compiler/java/java_field.h
  23. 23
      src/google/protobuf/compiler/java/java_helpers.cc
  24. 8
      src/google/protobuf/compiler/java/java_helpers.h
  25. 12
      src/google/protobuf/compiler/java/java_message_field.cc
  26. 6
      src/google/protobuf/compiler/java/java_message_field.h
  27. 6
      src/google/protobuf/compiler/java/java_message_field_lite.cc
  28. 3
      src/google/protobuf/compiler/java/java_message_field_lite.h
  29. 9
      src/google/protobuf/compiler/java/java_message_lite.cc
  30. 1
      src/google/protobuf/compiler/java/java_message_lite.h
  31. 12
      src/google/protobuf/compiler/java/java_primitive_field.cc
  32. 6
      src/google/protobuf/compiler/java/java_primitive_field.h
  33. 2
      src/google/protobuf/compiler/java/java_primitive_field_lite.cc
  34. 2
      src/google/protobuf/compiler/java/java_primitive_field_lite.h
  35. 12
      src/google/protobuf/compiler/java/java_string_field.cc
  36. 6
      src/google/protobuf/compiler/java/java_string_field.h
  37. 11
      src/google/protobuf/compiler/java/java_string_field_lite.cc
  38. 12
      src/google/protobuf/compiler/java/java_string_field_lite.h
  39. 2
      src/google/protobuf/compiler/js/js_generator.h
  40. 6
      src/google/protobuf/descriptor.cc
  41. 1
      src/google/protobuf/descriptor.h
  42. 29
      src/google/protobuf/io/coded_stream_unittest.cc
  43. 2
      src/google/protobuf/io/zero_copy_stream_impl_lite.cc
  44. 3
      src/google/protobuf/io/zero_copy_stream_impl_lite.h
  45. 6
      src/google/protobuf/map_field_test.cc
  46. 15
      src/google/protobuf/message.h
  47. 7
      src/google/protobuf/util/internal/constants.h
  48. 16
      src/google/protobuf/util/internal/datapiece.h
  49. 91
      src/google/protobuf/util/message_differencer.cc
  50. 37
      src/google/protobuf/util/message_differencer.h
  51. 4
      src/google/protobuf/util/type_resolver_util_test.cc
  52. 8
      src/google/protobuf/wire_format_lite.h
  53. 16
      src/google/protobuf/wrappers.pb.cc

@ -683,4 +683,5 @@ public final class Internal {
@Override
FloatList mutableCopyWithCapacity(int capacity);
}
}

@ -1041,18 +1041,21 @@ int DeleteRepeatedField(
// Remove items, starting from the end.
for (; length > to; length--) {
// If there is a living weak reference to a deleted item, we "Release" it,
if (field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
self->child_submessages) {
Message* sub_message = reflection->MutableRepeatedMessage(
message, field_descriptor, length - 1);
if (CMessage* released = self->MaybeReleaseSubMessage(sub_message)) {
released->message = reflection->ReleaseLast(message, field_descriptor);
continue;
}
if (field_descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
reflection->RemoveLast(message, field_descriptor);
continue;
}
// It seems that RemoveLast() is less efficient for sub-messages, and
// the memory is not completely released. Prefer ReleaseLast().
Message* sub_message = reflection->ReleaseLast(message, field_descriptor);
// If there is a live weak reference to an item being removed, we "Release"
// it, and it takes ownership of the message.
if (CMessage* released = self->MaybeReleaseSubMessage(sub_message)) {
released->message = sub_message;
} else {
// sub_message was not transferred, delete it.
delete sub_message;
}
// No Python object refers to this item, discard the value.
reflection->RemoveLast(message, field_descriptor);
}
return 0;

@ -132,6 +132,7 @@ class MockGeneratorContext : public GeneratorContext {
const char kDescriptorParameter[] = "dllexport_decl=PROTOBUF_EXPORT";
const char kPluginParameter[] = "dllexport_decl=PROTOC_EXPORT";
const char* test_protos[][2] = {
{"google/protobuf/descriptor", kDescriptorParameter},
{"google/protobuf/compiler/plugin", kPluginParameter},

@ -127,9 +127,7 @@ void FieldGenerator::GenerateMergeFromCodedStreamWithPacking(
FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor,
const Options& options,
MessageSCCAnalyzer* scc_analyzer)
: descriptor_(descriptor),
options_(options),
field_generators_(descriptor->field_count()) {
: descriptor_(descriptor), field_generators_(descriptor->field_count()) {
// Construct all the FieldGenerators.
for (int i = 0; i < descriptor->field_count(); i++) {
field_generators_[i].reset(

@ -227,7 +227,6 @@ class FieldGeneratorMap {
private:
const Descriptor* descriptor_;
const Options& options_;
std::vector<std::unique_ptr<FieldGenerator>> field_generators_;
static FieldGenerator* MakeGoogleInternalGenerator(

@ -166,20 +166,6 @@ static std::unordered_set<std::string>* MakeKeywordsMap() {
static std::unordered_set<std::string>& kKeywords = *MakeKeywordsMap();
// Returns whether the provided descriptor has an extension. This includes its
// nested types.
bool HasExtension(const Descriptor* descriptor) {
if (descriptor->extension_count() > 0) {
return true;
}
for (int i = 0; i < descriptor->nested_type_count(); ++i) {
if (HasExtension(descriptor->nested_type(i))) {
return true;
}
}
return false;
}
// Encode [0..63] as 'A'-'Z', 'a'-'z', '0'-'9', '_'
char Base63Char(int value) {
GOOGLE_CHECK_GE(value, 0);

@ -177,8 +177,8 @@ bool EmitFieldNonDefaultCondition(io::Printer* printer,
} else if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
// Message fields still have has_$name$() methods.
format("if ($prefix$has_$name$()) {\n");
} else if (field->cpp_type() == FieldDescriptor::CPPTYPE_DOUBLE
|| field->cpp_type() == FieldDescriptor::CPPTYPE_FLOAT) {
} else if (field->cpp_type() == FieldDescriptor::CPPTYPE_DOUBLE ||
field->cpp_type() == FieldDescriptor::CPPTYPE_FLOAT) {
// Handle float comparison to prevent -Wfloat-equal warnings
format("if (!($prefix$$name$() <= 0 && $prefix$$name$() >= 0)) {\n");
} else {
@ -766,7 +766,8 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* printer) {
format.Set("camel_oneof_name", UnderscoresToCamelCase(oneof->name(), true));
format(
"void ${1$clear_$oneof_name$$}$();\n"
"$camel_oneof_name$Case $oneof_name$_case() const;\n", oneof);
"$camel_oneof_name$Case $oneof_name$_case() const;\n",
oneof);
}
}
@ -1551,7 +1552,8 @@ void MessageGenerator::GenerateInlineMethods(io::Printer* printer) {
"${1$$oneof_name$_case$}$() const {\n"
" return $classname$::$camel_oneof_name$Case("
"_oneof_case_[$oneof_index$]);\n"
"}\n", oneof);
"}\n",
oneof);
}
}
@ -2745,21 +2747,6 @@ void MessageGenerator::GenerateSourceInProto2Namespace(io::Printer* printer) {
MessageCreateFunction(descriptor_));
}
bool MessageGenerator::MaybeGenerateOptionalFieldCondition(
io::Printer* printer, const FieldDescriptor* field,
int expected_has_bits_index) {
Formatter format(printer, variables_);
int has_bit_index = has_bit_indices_[field->index()];
if (!field->options().weak() &&
expected_has_bits_index == has_bit_index / 32) {
const std::string mask =
StrCat(strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8));
format("if (cached_has_bits & 0x$1$u) {\n", mask);
return true;
}
return false;
}
void MessageGenerator::GenerateClear(io::Printer* printer) {
Formatter format(printer, variables_);
// Performance tuning parameters

@ -135,13 +135,6 @@ class MessageGenerator {
// Generate the arena-specific destructor code.
void GenerateArenaDestructorCode(io::Printer* printer);
// Helper for GenerateClear and others. Optionally emits a condition that
// assumes the existence of the cached_has_bits variable, and returns true
// if the condition was printed.
bool MaybeGenerateOptionalFieldCondition(io::Printer* printer,
const FieldDescriptor* field,
int expected_has_bits_index);
// Generate standard Message methods.
void GenerateClear(io::Printer* printer);
void GenerateOneofClear(io::Printer* printer);

@ -44,7 +44,6 @@ namespace compiler {
namespace cpp {
namespace {
string ReinterpretCast(const string& type, const string& expression,
bool implicit_weak_field) {
if (implicit_weak_field) {

@ -167,14 +167,6 @@ void ServiceGenerator::GenerateMethodSignatures(VirtualOrNon virtual_or_non,
// ===================================================================
void ServiceGenerator::GenerateDescriptorInitializer(io::Printer* printer,
int index) {
Formatter format(printer, vars_);
format("$classname$_descriptor_ = file->service($1$);\n", index);
}
// ===================================================================
void ServiceGenerator::GenerateImplementation(io::Printer* printer) {
Formatter format(printer, vars_);
format(

@ -69,10 +69,6 @@ class ServiceGenerator {
// Source file stuff.
// Generate code that initializes the global variable storing the service's
// descriptor.
void GenerateDescriptorInitializer(io::Printer* printer, int index);
// Generate implementations of everything declared by
// GenerateDeclarations().
void GenerateImplementation(io::Printer* printer);

@ -137,10 +137,7 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
ImmutableEnumFieldGenerator::ImmutableEnumFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
builderBitIndex_(builderBitIndex),
name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetEnumVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor), name_resolver_,
&variables_);
@ -588,11 +585,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateHashCode(
RepeatedImmutableEnumFieldGenerator::RepeatedImmutableEnumFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
builderBitIndex_(builderBitIndex),
context_(context),
name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetEnumVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor), name_resolver_,
&variables_);

@ -86,9 +86,6 @@ class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator {
protected:
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
ClassNameResolver* name_resolver_;
private:
@ -147,9 +144,6 @@ class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator {
private:
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
ClassNameResolver* name_resolver_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableEnumFieldGenerator);

@ -280,42 +280,6 @@ void ImmutableEnumFieldLiteGenerator::GenerateInitializationCode(
}
}
void ImmutableEnumFieldLiteGenerator::GenerateFieldInfo(
io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
if (descriptor_->is_required()) {
printer->Print(
variables_,
"fieldInfoForProto2Required(\n"
" reflectField($classname$.class, \"$name$_\"),\n"
" $number$,\n"
" com.google.protobuf.FieldType.$annotation_field_type$,\n"
" $bit_field_name$,\n"
" $bit_field_mask$,\n"
" false,\n"
" $type$.internalGetValueMap())");
} else {
printer->Print(
variables_,
"fieldInfoForProto2Optional(\n"
" reflectField($classname$.class, \"$name$_\"),\n"
" $number$,\n"
" com.google.protobuf.FieldType.$annotation_field_type$,\n"
" $bit_field_name$,\n"
" $bit_field_mask$,\n"
" false,\n"
" $type$.internalGetValueMap())");
}
} else {
printer->Print(
variables_,
"fieldInfoWithEnumMap(\n"
" reflectField($classname$.class, \"$name$_\"),\n"
" $number$,\n"
" com.google.protobuf.FieldType.$annotation_field_type$,\n"
" $type$.internalGetValueMap())");
}
}
void ImmutableEnumFieldLiteGenerator::GenerateFieldInfo(
io::Printer* printer, std::vector<uint16>* output) const {
WriteIntToUtf16CharSequence(descriptor_->number(), output);
@ -416,15 +380,6 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateMembers(
"}\n");
}
void ImmutableEnumOneofFieldLiteGenerator::GenerateFieldInfo(
io::Printer* printer) const {
printer->Print(variables_,
"fieldInfoForOneofEnum(\n"
" $number$,\n"
" $oneof_name$_,\n"
" $oneof_stored_type$.class,\n"
" $type$.internalGetValueMap())");
}
void ImmutableEnumOneofFieldLiteGenerator::GenerateFieldInfo(
io::Printer* printer, std::vector<uint16>* output) const {
WriteIntToUtf16CharSequence(descriptor_->number(), output);
@ -504,7 +459,6 @@ RepeatedImmutableEnumFieldLiteGenerator::
int messageBitIndex,
Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
context_(context),
name_resolver_(context->GetNameResolver()) {
SetEnumVariables(descriptor, messageBitIndex, 0,
@ -678,15 +632,6 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers(
}
}
void RepeatedImmutableEnumFieldLiteGenerator::GenerateFieldInfo(
io::Printer* printer) const {
printer->Print(variables_,
"fieldInfoWithEnumMap(\n"
" reflectField($classname$.class, \"$name$_\"),\n"
" $number$,\n"
" com.google.protobuf.FieldType.$annotation_field_type$,\n"
" $type$.internalGetValueMap())");
}
void RepeatedImmutableEnumFieldLiteGenerator::GenerateFieldInfo(
io::Printer* printer, std::vector<uint16>* output) const {
WriteIntToUtf16CharSequence(descriptor_->number(), output);

@ -69,7 +69,6 @@ class ImmutableEnumFieldLiteGenerator : public ImmutableFieldLiteGenerator {
void GenerateMembers(io::Printer* printer) const;
void GenerateBuilderMembers(io::Printer* printer) const;
void GenerateInitializationCode(io::Printer* printer) const;
void GenerateFieldInfo(io::Printer* printer) const;
void GenerateFieldInfo(io::Printer* printer,
std::vector<uint16>* output) const;
@ -95,7 +94,6 @@ class ImmutableEnumOneofFieldLiteGenerator
void GenerateMembers(io::Printer* printer) const;
void GenerateBuilderMembers(io::Printer* printer) const;
void GenerateFieldInfo(io::Printer* printer) const;
void GenerateFieldInfo(io::Printer* printer,
std::vector<uint16>* output) const;
@ -116,7 +114,6 @@ class RepeatedImmutableEnumFieldLiteGenerator
void GenerateMembers(io::Printer* printer) const;
void GenerateBuilderMembers(io::Printer* printer) const;
void GenerateInitializationCode(io::Printer* printer) const;
void GenerateFieldInfo(io::Printer* printer) const;
void GenerateFieldInfo(io::Printer* printer,
std::vector<uint16>* output) const;
@ -125,7 +122,6 @@ class RepeatedImmutableEnumFieldLiteGenerator
private:
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
Context* context_;
ClassNameResolver* name_resolver_;

@ -223,18 +223,6 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
printer->Print("}\n\n");
}
bool EnumLiteGenerator::CanUseEnumValues() {
if (canonical_values_.size() != descriptor_->value_count()) {
return false;
}
for (int i = 0; i < descriptor_->value_count(); i++) {
if (descriptor_->value(i)->name() != canonical_values_[i]->name()) {
return false;
}
}
return true;
}
} // namespace java
} // namespace compiler
} // namespace protobuf

@ -87,8 +87,6 @@ class EnumLiteGenerator {
Context* context_;
ClassNameResolver* name_resolver_;
bool CanUseEnumValues();
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumLiteGenerator);
};

@ -49,9 +49,7 @@ namespace java {
ImmutableExtensionGenerator::ImmutableExtensionGenerator(
const FieldDescriptor* descriptor, Context* context)
: descriptor_(descriptor),
context_(context),
name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
if (descriptor_->extension_scope() != NULL) {
scope_ =
name_resolver_->GetImmutableClassName(descriptor_->extension_scope());

@ -100,7 +100,6 @@ class ImmutableExtensionGenerator : public ExtensionGenerator {
protected:
const FieldDescriptor* descriptor_;
Context* context_;
ClassNameResolver* name_resolver_;
std::string scope_;

@ -44,9 +44,7 @@ namespace java {
ImmutableExtensionLiteGenerator::ImmutableExtensionLiteGenerator(
const FieldDescriptor* descriptor, Context* context)
: descriptor_(descriptor),
context_(context),
name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
if (descriptor_->extension_scope() != NULL) {
scope_ =
name_resolver_->GetImmutableClassName(descriptor_->extension_scope());

@ -61,7 +61,6 @@ class ImmutableExtensionLiteGenerator : public ExtensionGenerator {
private:
const FieldDescriptor* descriptor_;
Context* context_;
ClassNameResolver* name_resolver_;
std::string scope_;

@ -124,8 +124,6 @@ class FieldGeneratorMap {
private:
const Descriptor* descriptor_;
Context* context_;
ClassNameResolver* name_resolver_;
std::vector<std::unique_ptr<FieldGeneratorType>> field_generators_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap);

@ -267,29 +267,6 @@ std::string JavaPackageToDir(std::string package_name) {
return package_dir;
}
// TODO(xiaofeng): This function is only kept for it's publicly referenced.
// It should be removed after mutable API up-integration.
std::string ToJavaName(const std::string& full_name,
const FileDescriptor* file) {
std::string result;
if (file->options().java_multiple_files()) {
result = FileJavaPackage(file);
} else {
result = ClassName(file);
}
if (!result.empty()) {
result += '.';
}
if (file->package().empty()) {
result += full_name;
} else {
// Strip the proto package from full_name since we've replaced it with
// the Java package.
result += full_name.substr(file->package().size() + 1);
}
return result;
}
std::string ClassName(const Descriptor* descriptor) {
ClassNameResolver name_resolver;
return name_resolver.GetClassName(descriptor, true);

@ -111,14 +111,6 @@ std::string FileJavaPackage(const FileDescriptor* file, bool immutable);
// Returns output directory for the given package name.
std::string JavaPackageToDir(std::string package_name);
// Converts the given fully-qualified name in the proto namespace to its
// fully-qualified name in the Java namespace, given that it is in the given
// file.
// TODO(xiaofeng): this method is deprecated and should be removed in the
// future.
std::string ToJavaName(const std::string& full_name,
const FileDescriptor* file);
// TODO(xiaofeng): the following methods are kept for they are exposed
// publicly in //net/proto2/compiler/java/public/names.h. They return
// immutable names only and should be removed after mutable API is

@ -122,11 +122,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
ImmutableMessageFieldGenerator::ImmutableMessageFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
builderBitIndex_(builderBitIndex),
context_(context),
name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetMessageVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
@ -799,11 +795,7 @@ void ImmutableMessageOneofFieldGenerator::GenerateSerializedSizeCode(
RepeatedImmutableMessageFieldGenerator::RepeatedImmutableMessageFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
builderBitIndex_(builderBitIndex),
context_(context),
name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetMessageVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);

@ -87,9 +87,6 @@ class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator {
protected:
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
ClassNameResolver* name_resolver_;
void PrintNestedBuilderCondition(io::Printer* printer,
@ -155,9 +152,6 @@ class RepeatedImmutableMessageFieldGenerator : public ImmutableFieldGenerator {
protected:
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
ClassNameResolver* name_resolver_;
void PrintNestedBuilderCondition(io::Printer* printer,

@ -107,7 +107,6 @@ ImmutableMessageFieldLiteGenerator::ImmutableMessageFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
context_(context),
name_resolver_(context->GetNameResolver()) {
SetMessageVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
@ -472,10 +471,7 @@ RepeatedImmutableMessageFieldLiteGenerator::
RepeatedImmutableMessageFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex,
Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
context_(context),
name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetMessageVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);

@ -78,7 +78,6 @@ class ImmutableMessageFieldLiteGenerator : public ImmutableFieldLiteGenerator {
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
Context* context_;
ClassNameResolver* name_resolver_;
private:
@ -123,8 +122,6 @@ class RepeatedImmutableMessageFieldLiteGenerator
protected:
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
Context* context_;
ClassNameResolver* name_resolver_;
private:

@ -65,15 +65,6 @@ namespace java {
using internal::WireFormat;
using internal::WireFormatLite;
namespace {
std::string MapValueImmutableClassdName(const Descriptor* descriptor,
ClassNameResolver* name_resolver) {
const FieldDescriptor* value_field = descriptor->FindFieldByName("value");
GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, value_field->type());
return name_resolver->GetImmutableClassName(value_field->message_type());
}
} // namespace
// ===================================================================
ImmutableMessageLiteGenerator::ImmutableMessageLiteGenerator(
const Descriptor* descriptor, Context* context)

@ -63,7 +63,6 @@ class ImmutableMessageLiteGenerator : public MessageGenerator {
void GenerateBuilder(io::Printer* printer);
void GenerateDynamicMethodNewBuilder(io::Printer* printer);
void GenerateInitializers(io::Printer* printer);
void GenerateEqualsAndHashCode(io::Printer* printer);
void GenerateParser(io::Printer* printer);
void GenerateConstructor(io::Printer* printer);
void GenerateDynamicMethodNewBuildMessageInfo(io::Printer* printer);

@ -187,11 +187,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
ImmutablePrimitiveFieldGenerator::ImmutablePrimitiveFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
builderBitIndex_(builderBitIndex),
context_(context),
name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
@ -627,11 +623,7 @@ RepeatedImmutablePrimitiveFieldGenerator::
int messageBitIndex,
int builderBitIndex,
Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
builderBitIndex_(builderBitIndex),
context_(context),
name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);

@ -87,9 +87,6 @@ class ImmutablePrimitiveFieldGenerator : public ImmutableFieldGenerator {
protected:
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
ClassNameResolver* name_resolver_;
private:
@ -148,9 +145,6 @@ class RepeatedImmutablePrimitiveFieldGenerator
private:
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
ClassNameResolver* name_resolver_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutablePrimitiveFieldGenerator);

@ -183,7 +183,6 @@ ImmutablePrimitiveFieldLiteGenerator::ImmutablePrimitiveFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
context_(context),
name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
@ -444,7 +443,6 @@ RepeatedImmutablePrimitiveFieldLiteGenerator::
const FieldDescriptor* descriptor, int messageBitIndex,
Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
context_(context),
name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, 0,

@ -78,7 +78,6 @@ class ImmutablePrimitiveFieldLiteGenerator
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
Context* context_;
ClassNameResolver* name_resolver_;
private:
@ -124,7 +123,6 @@ class RepeatedImmutablePrimitiveFieldLiteGenerator
private:
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
Context* context_;
ClassNameResolver* name_resolver_;

@ -139,11 +139,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
ImmutableStringFieldGenerator::ImmutableStringFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
builderBitIndex_(builderBitIndex),
context_(context),
name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
@ -708,11 +704,7 @@ void ImmutableStringOneofFieldGenerator::GenerateSerializedSizeCode(
RepeatedImmutableStringFieldGenerator::RepeatedImmutableStringFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
builderBitIndex_(builderBitIndex),
context_(context),
name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);

@ -87,9 +87,6 @@ class ImmutableStringFieldGenerator : public ImmutableFieldGenerator {
protected:
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
ClassNameResolver* name_resolver_;
private:
@ -146,9 +143,6 @@ class RepeatedImmutableStringFieldGenerator : public ImmutableFieldGenerator {
private:
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
ClassNameResolver* name_resolver_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableStringFieldGenerator);

@ -123,7 +123,6 @@ ImmutableStringFieldLiteGenerator::ImmutableStringFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
context_(context),
name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
@ -489,10 +488,7 @@ RepeatedImmutableStringFieldLiteGenerator::
RepeatedImmutableStringFieldLiteGenerator(const FieldDescriptor* descriptor,
int messageBitIndex,
Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
context_(context),
name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
@ -702,11 +698,6 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateBuilderMembers(
printer->Annotate("{", "}", descriptor_);
}
void RepeatedImmutableStringFieldLiteGenerator::
GenerateFieldBuilderInitializationCode(io::Printer* printer) const {
// noop for strings
}
void RepeatedImmutableStringFieldLiteGenerator::GenerateFieldInfo(
io::Printer* printer, std::vector<uint16>* output) const {
WriteIntToUtf16CharSequence(descriptor_->number(), output);

@ -79,7 +79,6 @@ class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator {
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
Context* context_;
ClassNameResolver* name_resolver_;
private:
@ -115,15 +114,6 @@ class RepeatedImmutableStringFieldLiteGenerator
void GenerateMembers(io::Printer* printer) const;
void GenerateBuilderMembers(io::Printer* printer) const;
void GenerateInitializationCode(io::Printer* printer) const;
void GenerateVisitCode(io::Printer* printer) const;
void GenerateDynamicMethodMakeImmutableCode(io::Printer* printer) const;
void GenerateParsingCode(io::Printer* printer) const;
void GenerateParsingDoneCode(io::Printer* printer) const;
void GenerateSerializationCode(io::Printer* printer) const;
void GenerateSerializedSizeCode(io::Printer* printer) const;
void GenerateFieldBuilderInitializationCode(io::Printer* printer) const;
void GenerateEqualsCode(io::Printer* printer) const;
void GenerateHashCode(io::Printer* printer) const;
void GenerateFieldInfo(io::Printer* printer,
std::vector<uint16>* output) const;
@ -132,8 +122,6 @@ class RepeatedImmutableStringFieldLiteGenerator
private:
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
Context* context_;
ClassNameResolver* name_resolver_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableStringFieldLiteGenerator);

@ -278,8 +278,6 @@ class PROTOC_EXPORT Generator : public CodeGenerator {
void GenerateClassFieldFromObject(const GeneratorOptions& options,
io::Printer* printer,
const FieldDescriptor* field) const;
void GenerateClassClone(const GeneratorOptions& options, io::Printer* printer,
const Descriptor* desc) const;
void GenerateClassRegistration(const GeneratorOptions& options,
io::Printer* printer,
const Descriptor* desc) const;

@ -3874,7 +3874,8 @@ Symbol DescriptorPool::NewPlaceholderWithMutexHeld(
placeholder_enum->values_ = tables_->AllocateArray<EnumValueDescriptor>(1);
EnumValueDescriptor* placeholder_value = &placeholder_enum->values_[0];
memset(static_cast<void*>(placeholder_value), 0, sizeof(*placeholder_value));
memset(static_cast<void*>(placeholder_value), 0,
sizeof(*placeholder_value));
placeholder_value->name_ = tables_->AllocateString("PLACEHOLDER_VALUE");
// Note that enum value names are siblings of their type, not children.
@ -3894,7 +3895,8 @@ Symbol DescriptorPool::NewPlaceholderWithMutexHeld(
placeholder_file->message_types_ = tables_->AllocateArray<Descriptor>(1);
Descriptor* placeholder_message = &placeholder_file->message_types_[0];
memset(static_cast<void*>(placeholder_message), 0, sizeof(*placeholder_message));
memset(static_cast<void*>(placeholder_message), 0,
sizeof(*placeholder_message));
placeholder_message->full_name_ = placeholder_full_name;
placeholder_message->name_ = placeholder_name;

@ -887,7 +887,6 @@ class PROTOBUF_EXPORT OneofDescriptor {
const std::string* name_;
const std::string* full_name_;
const Descriptor* containing_type_;
bool is_extendable_;
int field_count_;
const FieldDescriptor** fields_;
const OneofOptions* options_;

@ -131,13 +131,6 @@ namespace {
class CodedStreamTest : public testing::Test {
protected:
// Helper method used by tests for bytes warning. See implementation comment
// for further information.
static void SetupTotalBytesLimitWarningTest(
int total_bytes_limit, int warning_threshold,
std::vector<std::string>* out_errors,
std::vector<std::string>* out_warnings);
// Buffer used during most of the tests. This assumes tests run sequentially.
static const int kBufferSize = 1024 * 64;
static uint8 buffer_[kBufferSize];
@ -1278,28 +1271,6 @@ TEST_F(CodedStreamTest, TotalBytesLimitNotValidMessageEnd) {
EXPECT_FALSE(coded_input.ConsumedEntireMessage());
}
// This method is used by the tests below.
// It constructs a CodedInputStream with the given limits and tries to read 2KiB
// of data from it. Then it returns the logged errors and warnings in the given
// vectors.
void CodedStreamTest::SetupTotalBytesLimitWarningTest(
int total_bytes_limit, int warning_threshold,
std::vector<std::string>* out_errors,
std::vector<std::string>* out_warnings) {
ArrayInputStream raw_input(buffer_, sizeof(buffer_), 128);
ScopedMemoryLog scoped_log;
{
CodedInputStream input(&raw_input);
input.SetTotalBytesLimit(total_bytes_limit, warning_threshold);
std::string str;
EXPECT_TRUE(input.ReadString(&str, 2048));
}
*out_errors = scoped_log.GetMessages(ERROR);
*out_warnings = scoped_log.GetMessages(WARNING);
}
TEST_F(CodedStreamTest, RecursionLimit) {
ArrayInputStream input(buffer_, sizeof(buffer_));
CodedInputStream coded_input(&input);

@ -181,8 +181,6 @@ int64 StringOutputStream::ByteCount() const {
return target_->size();
}
void StringOutputStream::SetString(std::string* target) { target_ = target; }
// ===================================================================
int CopyingInputStream::Skip(int count) {

@ -147,9 +147,6 @@ class PROTOBUF_EXPORT StringOutputStream : public ZeroCopyOutputStream {
void BackUp(int count) override;
int64 ByteCount() const override;
protected:
void SetString(std::string* target);
private:
static const int kMinimumSize = 16;

@ -79,11 +79,13 @@ class MapFieldBaseStub : public MapFieldBase {
state_.store(STATE_MODIFIED_REPEATED, std::memory_order_relaxed);
}
bool ContainsMapKey(const MapKey& map_key) const override { return false; }
bool InsertOrLookupMapValue(const MapKey& map_key, MapValueRef* val) override {
bool InsertOrLookupMapValue(const MapKey& map_key,
MapValueRef* val) override {
return false;
}
bool DeleteMapValue(const MapKey& map_key) override { return false; }
bool EqualIterator(const MapIterator& a, const MapIterator& b) const override {
bool EqualIterator(const MapIterator& a,
const MapIterator& b) const override {
return false;
}
int size() const override { return 0; }

@ -1179,21 +1179,6 @@ void LinkMessageReflection() {
(void)&unused; // Use address to avoid an extra load of volatile variable.
}
namespace internal {
// Legacy functions, to preserve compatibility with existing callers.
// These had a slightly different signature, so we have to adjust "T".
template <typename T>
T dynamic_cast_if_available(const Message* from) {
return DynamicCastToGenerated<typename std::remove_pointer<T>::type>(from);
}
template <typename T>
T dynamic_cast_if_available(Message* from) {
return DynamicCastToGenerated<typename std::remove_pointer<T>::type>(from);
}
} // namespace internal
// =============================================================================
// Implementation details for {Get,Mutable}RawRepeatedPtrField. We provide
// specializations for <std::string>, <StringPieceField> and <Message> and

@ -86,16 +86,9 @@ const char kDurationType[] = "google.protobuf.Duration";
// Type URL for struct value type google.protobuf.Value
const char kStructValueTypeUrl[] = "type.googleapis.com/google.protobuf.Value";
// Type URL for struct value type google.protobuf.Value
const char kStructTypeUrl[] = "type.googleapis.com/google.protobuf.Struct";
// Type string for google.protobuf.Any
const char kAnyType[] = "google.protobuf.Any";
// The type URL of google.protobuf.FieldMask;
const char kFieldMaskTypeUrl[] =
"type.googleapis.com/google.protobuf.FieldMask";
// The protobuf option name of jspb.message_id;
const char kOptionJspbMessageId[] = "jspb.message_id";

@ -154,22 +154,6 @@ class PROTOBUF_EXPORT DataPiece {
util::StatusOr<std::string> ToBytes() const;
// Converts a value into protocol buffer enum number. If the value is a
// string, first attempts conversion by name, trying names as follows:
// 1) the directly provided string value.
// 2) the value upper-cased and replacing '-' by '_'
// 3) if use_lower_camel_for_enums is true it also attempts by comparing
// enum name without underscore with the value upper cased above.
// If the value is not a string, attempts to convert to a 32-bit integer.
// If none of these succeeds, returns a conversion error status.
util::StatusOr<int> ToEnum(const google::protobuf::Enum* enum_type,
bool use_lower_camel_for_enums) const {
return ToEnum(enum_type, use_lower_camel_for_enums,
/* ignore_unknown_enum_values */ false,
/* case_insensitive_enum_parsing */ true,
/* is_unknown_enum_value */ nullptr);
}
private:
friend class ProtoWriter;

@ -53,6 +53,7 @@
#include <google/protobuf/stubs/strutil.h>
// Always include as last one, otherwise it can break compilation
#include <google/protobuf/port_def.inc>
namespace google {
@ -512,14 +513,20 @@ bool MessageDifferencer::CompareWithFields(
bool result = false;
std::vector<const FieldDescriptor*> message1_fields(message1_fields_arg);
std::vector<const FieldDescriptor*> message2_fields(message2_fields_arg);
FieldDescriptorArray message1_fields(message1_fields_arg.size() + 1);
FieldDescriptorArray message2_fields(message2_fields_arg.size() + 1);
std::copy(message1_fields_arg.cbegin(), message1_fields_arg.cend(),
message1_fields.begin());
std::copy(message2_fields_arg.cbegin(), message2_fields_arg.cend(),
message2_fields.begin());
// Append sentinel values.
message1_fields[message1_fields_arg.size()] = nullptr;
message2_fields[message2_fields_arg.size()] = nullptr;
std::sort(message1_fields.begin(), message1_fields.end(), FieldBefore);
std::sort(message2_fields.begin(), message2_fields.end(), FieldBefore);
// Append NULL sentinel values.
message1_fields.push_back(NULL);
message2_fields.push_back(NULL);
// Setup the internal reporter if need be.
if (output_string_) {
@ -579,10 +586,8 @@ bool MessageDifferencer::Compare(const Message& message1,
}
}
std::vector<const FieldDescriptor*> message1_fields =
RetrieveFields(message1, true);
std::vector<const FieldDescriptor*> message2_fields =
RetrieveFields(message2, false);
FieldDescriptorArray message1_fields = RetrieveFields(message1, true);
FieldDescriptorArray message2_fields = RetrieveFields(message2, false);
return CompareRequestedFieldsUsingSettings(
message1, message2,
@ -590,48 +595,49 @@ bool MessageDifferencer::Compare(const Message& message1,
parent_fields) && unknown_compare_result;
}
std::vector<const FieldDescriptor*> MessageDifferencer::RetrieveFields(
const Message& message, bool base_message) {
FieldDescriptorArray MessageDifferencer::RetrieveFields(const Message& message,
bool base_message) {
const Descriptor* descriptor = message.GetDescriptor();
std::vector<const FieldDescriptor*> message_fields;
message_fields.reserve(descriptor->field_count() + 1);
tmp_message_fields_.clear();
tmp_message_fields_.reserve(descriptor->field_count() + 1);
const Reflection* reflection = message.GetReflection();
if (descriptor->options().map_entry()) {
if (this->scope_ == PARTIAL && base_message) {
reflection->ListFields(message, &message_fields);
reflection->ListFields(message, &tmp_message_fields_);
} else {
// Map entry fields are always considered present.
for (int i = 0; i < descriptor->field_count(); i++) {
message_fields.push_back(descriptor->field(i));
tmp_message_fields_.push_back(descriptor->field(i));
}
}
} else {
reflection->ListFields(message, &message_fields);
reflection->ListFields(message, &tmp_message_fields_);
}
// Add sentinel values to deal with the
// case where the number of the fields in
// each list are different.
message_fields.push_back(nullptr);
tmp_message_fields_.push_back(nullptr);
FieldDescriptorArray message_fields(tmp_message_fields_.begin(),
tmp_message_fields_.end());
return message_fields;
}
bool MessageDifferencer::CompareRequestedFieldsUsingSettings(
const Message& message1,
const Message& message2,
const std::vector<const FieldDescriptor*>& message1_fields,
const std::vector<const FieldDescriptor*>& message2_fields,
const Message& message1, const Message& message2,
const FieldDescriptorArray& message1_fields,
const FieldDescriptorArray& message2_fields,
std::vector<SpecificField>* parent_fields) {
if (scope_ == FULL) {
if (message_field_comparison_ == EQUIVALENT) {
// We need to merge the field lists of both messages (i.e.
// we are merely checking for a difference in field values,
// rather than the addition or deletion of fields).
std::vector<const FieldDescriptor*> fields_union;
CombineFields(message1_fields, FULL, message2_fields, FULL,
&fields_union);
FieldDescriptorArray fields_union =
CombineFields(message1_fields, FULL, message2_fields, FULL);
return CompareWithFieldsInternal(message1, message2, fields_union,
fields_union, parent_fields);
} else {
@ -651,52 +657,55 @@ bool MessageDifferencer::CompareRequestedFieldsUsingSettings(
// but only the intersection for message2. This way, any fields
// only present in message2 will be ignored, but any fields only
// present in message1 will be marked as a difference.
std::vector<const FieldDescriptor*> fields_intersection;
CombineFields(message1_fields, PARTIAL, message2_fields, PARTIAL,
&fields_intersection);
FieldDescriptorArray fields_intersection =
CombineFields(message1_fields, PARTIAL, message2_fields, PARTIAL);
return CompareWithFieldsInternal(message1, message2, message1_fields,
fields_intersection, parent_fields);
}
}
}
void MessageDifferencer::CombineFields(
const std::vector<const FieldDescriptor*>& fields1,
Scope fields1_scope,
const std::vector<const FieldDescriptor*>& fields2,
Scope fields2_scope,
std::vector<const FieldDescriptor*>* combined_fields) {
FieldDescriptorArray MessageDifferencer::CombineFields(
const FieldDescriptorArray& fields1, Scope fields1_scope,
const FieldDescriptorArray& fields2, Scope fields2_scope) {
int index1 = 0;
int index2 = 0;
tmp_message_fields_.clear();
while (index1 < fields1.size() && index2 < fields2.size()) {
const FieldDescriptor* field1 = fields1[index1];
const FieldDescriptor* field2 = fields2[index2];
if (FieldBefore(field1, field2)) {
if (fields1_scope == FULL) {
combined_fields->push_back(fields1[index1]);
tmp_message_fields_.push_back(fields1[index1]);
}
++index1;
} else if (FieldBefore(field2, field1)) {
if (fields2_scope == FULL) {
combined_fields->push_back(fields2[index2]);
tmp_message_fields_.push_back(fields2[index2]);
}
++index2;
} else {
combined_fields->push_back(fields1[index1]);
tmp_message_fields_.push_back(fields1[index1]);
++index1;
++index2;
}
}
tmp_message_fields_.push_back(nullptr);
FieldDescriptorArray combined_fields(tmp_message_fields_.begin(),
tmp_message_fields_.end());
return combined_fields;
}
bool MessageDifferencer::CompareWithFieldsInternal(
const Message& message1,
const Message& message2,
const std::vector<const FieldDescriptor*>& message1_fields,
const std::vector<const FieldDescriptor*>& message2_fields,
const Message& message1, const Message& message2,
const FieldDescriptorArray& message1_fields,
const FieldDescriptorArray& message2_fields,
std::vector<SpecificField>* parent_fields) {
bool isDifferent = false;
int field_index1 = 0;

@ -47,11 +47,13 @@
#include <set>
#include <string>
#include <vector>
#include <google/protobuf/descriptor.h> // FieldDescriptor
#include <google/protobuf/message.h> // Message
#include <google/protobuf/unknown_field_set.h>
#include <google/protobuf/util/field_comparator.h>
// Always include as last one, otherwise it can break compilation
#include <google/protobuf/port_def.inc>
namespace google {
@ -70,6 +72,12 @@ namespace util {
class DefaultFieldComparator;
class FieldContext; // declared below MessageDifferencer
// Defines a collection of field descriptors.
// In case of internal google codebase we are using absl::FixedArray instead
// of vector. It significantly speeds up proto comparison (by ~30%) by
// reducing the number of malloc/free operations
typedef std::vector<const FieldDescriptor*> FieldDescriptorArray;
// A basic differencer that can be used to determine
// the differences between two specified Protocol Messages. If any differences
// are found, the Compare method will return false, and any differencer reporter
@ -697,18 +705,17 @@ class PROTOBUF_EXPORT MessageDifferencer {
const FieldDescriptor* field2);
// Retrieve all the set fields, including extensions.
std::vector<const FieldDescriptor*> RetrieveFields(const Message& message,
bool base_message);
FieldDescriptorArray RetrieveFields(const Message& message,
bool base_message);
// Combine the two lists of fields into the combined_fields output vector.
// All fields present in both lists will always be included in the combined
// list. Fields only present in one of the lists will only appear in the
// combined list if the corresponding fields_scope option is set to FULL.
void CombineFields(const std::vector<const FieldDescriptor*>& fields1,
Scope fields1_scope,
const std::vector<const FieldDescriptor*>& fields2,
Scope fields2_scope,
std::vector<const FieldDescriptor*>* combined_fields);
FieldDescriptorArray CombineFields(const FieldDescriptorArray& fields1,
Scope fields1_scope,
const FieldDescriptorArray& fields2,
Scope fields2_scope);
// Internal version of the Compare method which performs the actual
// comparison. The parent_fields vector is a vector containing field
@ -728,16 +735,16 @@ class PROTOBUF_EXPORT MessageDifferencer {
// CompareWithFieldsInternal.
bool CompareRequestedFieldsUsingSettings(
const Message& message1, const Message& message2,
const std::vector<const FieldDescriptor*>& message1_fields,
const std::vector<const FieldDescriptor*>& message2_fields,
const FieldDescriptorArray& message1_fields,
const FieldDescriptorArray& message2_fields,
std::vector<SpecificField>* parent_fields);
// Compares the specified messages with the specified field lists.
bool CompareWithFieldsInternal(
const Message& message1, const Message& message2,
const std::vector<const FieldDescriptor*>& message1_fields,
const std::vector<const FieldDescriptor*>& message2_fields,
std::vector<SpecificField>* parent_fields);
bool CompareWithFieldsInternal(const Message& message1,
const Message& message2,
const FieldDescriptorArray& message1_fields,
const FieldDescriptorArray& message2_fields,
std::vector<SpecificField>* parent_fields);
// Compares the repeated fields, and report the error.
bool CompareRepeatedField(const Message& message1, const Message& message2,
@ -867,6 +874,8 @@ class PROTOBUF_EXPORT MessageDifferencer {
FieldKeyComparatorMap map_field_key_comparator_;
MapEntryKeyComparator map_entry_key_comparator_;
std::vector<IgnoreCriteria*> ignore_criteria_;
// Reused multiple times in RetrieveFields to avoid extra allocations
std::vector<const FieldDescriptor*> tmp_message_fields_;
FieldSet ignored_fields_;

@ -78,10 +78,6 @@ class DescriptorPoolTypeResolverTest : public testing::Test {
return NULL;
}
bool HasField(const Type& type, const std::string& name) {
return FindField(type, name) != NULL;
}
bool HasField(const Type& type, Field::Cardinality cardinality,
Field::Kind kind, const std::string& name, int number) {
const Field* field = FindField(type, name);

@ -338,14 +338,6 @@ class PROTOBUF_EXPORT WireFormatLite {
static inline bool ReadMessage(io::CodedInputStream* input,
MessageType* value);
// Do not use.
template <typename MessageType>
static inline bool ReadGroupNoVirtual(int field_number,
io::CodedInputStream* input,
MessageType* value) {
return ReadGroup(field_number, input, value);
}
template <typename MessageType>
static inline bool ReadMessageNoVirtual(io::CodedInputStream* input,
MessageType* value) {

@ -460,7 +460,7 @@ void DoubleValue::SerializeWithCachedSizes(
(void) cached_has_bits;
// double value = 1;
if (this->value() != 0) {
if (!(this->value() <= 0 && this->value() >= 0)) {
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteDouble(1, this->value(), output);
}
@ -478,7 +478,7 @@ void DoubleValue::SerializeWithCachedSizes(
(void) cached_has_bits;
// double value = 1;
if (this->value() != 0) {
if (!(this->value() <= 0 && this->value() >= 0)) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteDoubleToArray(1, this->value(), target);
}
@ -504,7 +504,7 @@ size_t DoubleValue::ByteSizeLong() const {
(void) cached_has_bits;
// double value = 1;
if (this->value() != 0) {
if (!(this->value() <= 0 && this->value() >= 0)) {
total_size += 1 + 8;
}
@ -535,7 +535,7 @@ void DoubleValue::MergeFrom(const DoubleValue& from) {
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
if (from.value() != 0) {
if (!(from.value() <= 0 && from.value() >= 0)) {
set_value(from.value());
}
}
@ -745,7 +745,7 @@ void FloatValue::SerializeWithCachedSizes(
(void) cached_has_bits;
// float value = 1;
if (this->value() != 0) {
if (!(this->value() <= 0 && this->value() >= 0)) {
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteFloat(1, this->value(), output);
}
@ -763,7 +763,7 @@ void FloatValue::SerializeWithCachedSizes(
(void) cached_has_bits;
// float value = 1;
if (this->value() != 0) {
if (!(this->value() <= 0 && this->value() >= 0)) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteFloatToArray(1, this->value(), target);
}
@ -789,7 +789,7 @@ size_t FloatValue::ByteSizeLong() const {
(void) cached_has_bits;
// float value = 1;
if (this->value() != 0) {
if (!(this->value() <= 0 && this->value() >= 0)) {
total_size += 1 + 4;
}
@ -820,7 +820,7 @@ void FloatValue::MergeFrom(const FloatValue& from) {
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
if (from.value() != 0) {
if (!(from.value() <= 0 && from.value() >= 0)) {
set_value(from.value());
}
}

Loading…
Cancel
Save