-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-collectionsArea: `std::collections`Area: `std::collections`A-iteratorsArea: IteratorsArea: IteratorsC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchE-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.I-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size 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.
Description
Box<[T]>
requires 2x assembly (96 -> 185) compared to Vec<T>
. I think this could be improved.
pub fn t<'a>(iter: &'a [&str]) -> Vec<&'a str> {
iter.iter().cloned().collect()
}
pub fn t<'a>(iter: &'a [&str]) -> Box<[&'a str]> {
iter.iter().cloned().collect()
}
Looking at the generated code, looks like some extra unnecessary checks were added.
hmm, some panic handling for "Tried to shrink to a larger capacity"
(which should be statically unreachable)
Is that even possible?
no, but I guess it isn't seeing that len<=capacity
@cuviper
However, this does not affect the following.
pub fn t<'a>() -> Box<[&'a str]> {
["a", "b"].iter().cloned().collect()
}
I will be taking a look at this in the meantime while looking at join
for Iterator
. I wish an assert
could solve this.
leonardo-m and ricvelozo
Metadata
Metadata
Assignees
Labels
A-collectionsArea: `std::collections`Area: `std::collections`A-iteratorsArea: IteratorsArea: IteratorsC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchE-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.I-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size 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.