Vec::append should swap if the lhs is empty #56763
Labels
C-optimization
Category: An issue highlighting optimization opportunities or PRs implementing such
I-slow
Issue: Problems and improvements with respect to performance of generated code.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Here's a reasonable pattern:
On the first append, we can just swap ourselves with the rhs, avoiding an allocation and copy. This is annoying for our users to remember to do, and is basically free to support given how much work this method otherwise does.
It should perhaps only be done if lhs.capacity is 0, just because we don't want to mess up a user who has preallocated a nice big buffer. Maybe lhs.capacity < rhs.capacity?
The text was updated successfully, but these errors were encountered: