-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Vec::pop() sometimes returns value inefficiently. #85365
Copy link
Copy link
Open
Labels
A-collectionsArea: `std::collections`Area: `std::collections`C-bugCategory: This is a bug.Category: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-collectionsArea: `std::collections`Area: `std::collections`C-bugCategory: This is a bug.Category: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I tried this code:
I expected to see this happen: The two functions generate similar assembly.
Instead, this happened:
Vec::pop()uses far less efficient copying.Meta
rustc --version --verbose:It also happens on Nightly, although the generated assembly is much better.
Edit: It appears to be related to an
Optionholding the value, because the same behaviour is observed when usingvec.get(vec.len() - 1).copied().unwrap()but not*vec.get(vec.len() - 1).unwrap().Playground Link