-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
Here's a reasonable pattern:
let mut results = Vec::new();
for ... {
results.append(new_results);
}
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?
scottmcm and jonasbb
Metadata
Metadata
Assignees
Labels
C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.