Skip to content

Commit

Permalink
Change LazyField to use a flat char array when the unparsed payload i…
Browse files Browse the repository at this point in the history
…s small. This array can easily be allocated in the arena avoiding separate heap usage of the Cord.

Also, we remove the ArenaDtor and register the Cord for destruction on demand.
This avoids registering the ArenaDtor on every message with a lazy field.

PiperOrigin-RevId: 620857434
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Apr 1, 2024
1 parent f0f7be2 commit 43fb62e
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 113 deletions.
7 changes: 4 additions & 3 deletions src/google/protobuf/compiler/cpp/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,8 @@ void MessageGenerator::GenerateImplDefinition(io::Printer* p) {
inline explicit Impl_($pbi$::InternalVisibility visibility,
::$proto_ns$::Arena* arena);
inline explicit Impl_($pbi$::InternalVisibility visibility,
::$proto_ns$::Arena* arena, const Impl_& from);
::$proto_ns$::Arena* arena, const Impl_& from,
const $classname$& from_msg);
//~ Members assumed to align to 8 bytes:
$extension_set$;
$tracker$;
Expand Down Expand Up @@ -2993,7 +2994,7 @@ void MessageGenerator::GenerateArenaEnabledCopyConstructor(io::Printer* p) {
R"cc(
inline PROTOBUF_NDEBUG_INLINE $classname$::Impl_::Impl_(
$pbi$::InternalVisibility visibility, ::$proto_ns$::Arena* arena,
const Impl_& from)
const Impl_& from, const $classtype$& from_msg)
//~
$init$ {}
)cc");
Expand All @@ -3003,7 +3004,7 @@ void MessageGenerator::GenerateArenaEnabledCopyConstructor(io::Printer* p) {
auto copy_construct_impl = [&] {
if (!HasSimpleBaseClass(descriptor_, options_)) {
p->Emit(R"cc(
new (&_impl_) Impl_(internal_visibility(), arena, from._impl_);
new (&_impl_) Impl_(internal_visibility(), arena, from._impl_, from);
)cc");
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/google/protobuf/compiler/java/java_features.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/google/protobuf/compiler/plugin.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions src/google/protobuf/compiler/plugin.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/google/protobuf/cpp_features.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 43fb62e

Please sign in to comment.