Skip to content

Conversation

@copybara-service
Copy link

Optimize RepeatedPtrField to use copy constructors where possible

The most common MergeFrom() scenario is that items are newly appended to an existing repeated field that has never been shrunk. For these cases copy constructing new entries is the cheapest option. This change overloads MergeFrom<> for std::string, StringPiece, Message and MessageLite, leaving the remaining templated implementation for all concrete message types supporting arena enabled copy construction, which is implemented as an out of line factory functor implementation.

Going forward we should change Arena::CreateMaybeMessage() to return MessageLite* and accept const MessageLite& for copy construction. This will allow us to directly pass Arena::CreateMaybeMessage() into these out of line functions.

The most common MergeFrom() scenario is that items are newly appended to an existing repeated field that has never been shrunk. For these cases copy constructing new entries is the cheapest option. This change overloads MergeFrom<> for `std::string`, `StringPiece`, `Message` and `MessageLite`, leaving the remaining templated implementation for all concrete message types supporting arena enabled copy construction, which is implemented as an out of line factory functor implementation.

Going forward we should change `Arena::CreateMaybeMessage()` to return MessageLite* and accept const MessageLite& for copy construction. This will allow us to directly pass Arena::CreateMaybeMessage<T>() into these out of line functions.

PiperOrigin-RevId: 568220325
@copybara-service copybara-service bot merged commit 617e191 into main Sep 25, 2023
@copybara-service copybara-service bot deleted the test_563438796 branch September 25, 2023 15:07
@github-pages github-pages bot temporarily deployed to github-pages September 25, 2023 15:08 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant