Skip to content

Commit

Permalink
When field tracking is enabled, use the normal base class.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 530711262
  • Loading branch information
protobuf-github-bot authored and copybara-github committed May 9, 2023
1 parent d4ef42a commit 95c5ed2
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/google/protobuf/compiler/cpp/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -705,13 +705,23 @@ bool UsingImplicitWeakFields(const FileDescriptor* file,
bool IsImplicitWeakField(const FieldDescriptor* field, const Options& options,
MessageSCCAnalyzer* scc_analyzer);

inline bool HasSimpleBaseClass(const Descriptor* desc, const Options& options) {
if (!HasDescriptorMethods(desc->file(), options)) return false;
if (desc->extension_range_count() != 0) return false;
if (desc->field_count() == 0) return true;
inline std::string SimpleBaseClass(const Descriptor* desc,
const Options& options) {
if (!HasDescriptorMethods(desc->file(), options)) return "";
if (desc->extension_range_count() != 0) return "";
// Don't use a simple base class if the field tracking is enabled. This
// ensures generating all methods to track.
if (options.field_listener_options.inject_field_listener_events) return "";
if (desc->field_count() == 0) {
return "ZeroFieldsBase";
}
// TODO(jorg): Support additional common message types with only one
// or two fields
return false;
return "";
}

inline bool HasSimpleBaseClass(const Descriptor* desc, const Options& options) {
return !SimpleBaseClass(desc, options).empty();
}

inline bool HasSimpleBaseClasses(const FileDescriptor* file,
Expand All @@ -723,18 +733,6 @@ inline bool HasSimpleBaseClasses(const FileDescriptor* file,
return v;
}

inline std::string SimpleBaseClass(const Descriptor* desc,
const Options& options) {
if (!HasDescriptorMethods(desc->file(), options)) return "";
if (desc->extension_range_count() != 0) return "";
if (desc->field_count() == 0) {
return "ZeroFieldsBase";
}
// TODO(jorg): Support additional common message types with only one
// or two fields
return "";
}

// Returns true if this message has a _tracker_ field.
inline bool HasTracker(const Descriptor* desc, const Options& options) {
return options.field_listener_options.inject_field_listener_events &&
Expand Down

0 comments on commit 95c5ed2

Please sign in to comment.