Skip to content

Commit

Permalink
Merge pull request #10960 from protocolbuffers/gberg-ads-performance
Browse files Browse the repository at this point in the history
Use bit-field int values in buildPartial to skip work on unset groups of fields.
  • Loading branch information
googleberg authored Nov 14, 2022
2 parents accd49b + b0f7bff commit 4f393bd
Show file tree
Hide file tree
Showing 13 changed files with 861 additions and 731 deletions.
181 changes: 87 additions & 94 deletions src/google/protobuf/compiler/java/enum_field.cc

Large diffs are not rendered by default.

32 changes: 17 additions & 15 deletions src/google/protobuf/compiler/java/enum_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <map>
#include <string>

#include <google/protobuf/compiler/java/field.h>
#include "google/protobuf/compiler/java/field.h"

namespace google {
namespace protobuf {
Expand All @@ -61,10 +61,15 @@ class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator {
explicit ImmutableEnumFieldGenerator(const FieldDescriptor* descriptor,
int messageBitIndex, int builderBitIndex,
Context* context);
ImmutableEnumFieldGenerator(const ImmutableEnumFieldGenerator&) = delete;
ImmutableEnumFieldGenerator& operator=(const ImmutableEnumFieldGenerator&) =
delete;
~ImmutableEnumFieldGenerator() override;

// implements ImmutableFieldGenerator
// ---------------------------------------
int GetMessageBitIndex() const override;
int GetBuilderBitIndex() const override;
int GetNumBitsForMessage() const override;
int GetNumBitsForBuilder() const override;
void GenerateInterfaceMembers(io::Printer* printer) const override;
Expand All @@ -87,18 +92,21 @@ class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator {

protected:
const FieldDescriptor* descriptor_;
int message_bit_index_;
int builder_bit_index_;
std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_;

private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumFieldGenerator);
};

class ImmutableEnumOneofFieldGenerator : public ImmutableEnumFieldGenerator {
public:
ImmutableEnumOneofFieldGenerator(const FieldDescriptor* descriptor,
int messageBitIndex, int builderBitIndex,
Context* context);
ImmutableEnumOneofFieldGenerator(const ImmutableEnumOneofFieldGenerator&) =
delete;
ImmutableEnumOneofFieldGenerator& operator=(
const ImmutableEnumOneofFieldGenerator&) = delete;
~ImmutableEnumOneofFieldGenerator() override;

void GenerateMembers(io::Printer* printer) const override;
Expand All @@ -111,16 +119,17 @@ class ImmutableEnumOneofFieldGenerator : public ImmutableEnumFieldGenerator {
void GenerateSerializedSizeCode(io::Printer* printer) const override;
void GenerateEqualsCode(io::Printer* printer) const override;
void GenerateHashCode(io::Printer* printer) const override;

private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumOneofFieldGenerator);
};

class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator {
class RepeatedImmutableEnumFieldGenerator : public ImmutableEnumFieldGenerator {
public:
explicit RepeatedImmutableEnumFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex,
int builderBitIndex, Context* context);
RepeatedImmutableEnumFieldGenerator(
const RepeatedImmutableEnumFieldGenerator&) = delete;
RepeatedImmutableEnumFieldGenerator& operator=(
const RepeatedImmutableEnumFieldGenerator&) = delete;
~RepeatedImmutableEnumFieldGenerator() override;

// implements ImmutableFieldGenerator ---------------------------------------
Expand All @@ -145,13 +154,6 @@ class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator {
void GenerateKotlinDslMembers(io::Printer* printer) const override;

std::string GetBoxedType() const override;

private:
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_;

GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableEnumFieldGenerator);
};

} // namespace java
Expand Down
2 changes: 2 additions & 0 deletions src/google/protobuf/compiler/java/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class ImmutableFieldGenerator {
ImmutableFieldGenerator() {}
virtual ~ImmutableFieldGenerator();

virtual int GetMessageBitIndex() const = 0;
virtual int GetBuilderBitIndex() const = 0;
virtual int GetNumBitsForMessage() const = 0;
virtual int GetNumBitsForBuilder() const = 0;
virtual void GenerateInterfaceMembers(io::Printer* printer) const = 0;
Expand Down
Loading

0 comments on commit 4f393bd

Please sign in to comment.