refactor(cli/rustup-mode): avoid redundant allocs in target_add() - #5054
Open
rami3l wants to merge 3 commits into
Open
refactor(cli/rustup-mode): avoid redundant allocs in target_add()#5054rami3l wants to merge 3 commits into
target_add()#5054rami3l wants to merge 3 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
rami3l
force-pushed
the
refactor/target-add-allocs
branch
2 times, most recently
from
September 4, 2026 14:21
e699869 to
83f5d81
Compare
rami3l
marked this pull request as ready for review
September 4, 2026 14:23
rami3l
force-pushed
the
refactor/target-add-allocs
branch
3 times, most recently
from
September 4, 2026 14:48
4b61a97 to
cb9dc23
Compare
djc
reviewed
Sep 4, 2026
Comment on lines
+1473
to
+1490
| match targets.iter().any(|it| it == "all") { | ||
| true if targets.len() == 1 => { | ||
| Either::Left(distributable.components()?.into_iter().filter_map(|c| { | ||
| (c.available && !c.installed && c.component.short_name() == "rust-std") | ||
| .then_some(c.component) | ||
| })) | ||
| } | ||
| true => { | ||
| return Err(anyhow!( | ||
| "`rustup target add {}` includes `all`", | ||
| targets.join(" "), | ||
| )); | ||
| } | ||
| false => Either::Right(targets.into_iter().map(|t| { | ||
| Component::new("rust-std".to_string(), Some(TargetTuple::new(t)), false) | ||
| })), | ||
| } | ||
| .collect(), |
Contributor
There was a problem hiding this comment.
I'd do something like this up front:
let all = targets.iter().any(|it| it == "all");
if all && targets.len() > 1 {
return Err(anyhow!(
"`rustup target add {}` includes `all`",
targets.join(" "),
));
}
Also, it looks like add_components() could take an impl ExactSizeIterator instead of a Vec<_>.
(You know this is just code golf and not a meaningful optimization, right?)
Member
Author
There was a problem hiding this comment.
Yeah I just have found the trunk code quite unreadable, and as I tried to simplify I just found out more issues...
Member
Author
There was a problem hiding this comment.
@djc I've minimized the diff, it should look better now?
rami3l
force-pushed
the
refactor/target-add-allocs
branch
5 times, most recently
from
September 4, 2026 15:19
72989ce to
00055a8
Compare
rami3l
force-pushed
the
refactor/target-add-allocs
branch
from
September 4, 2026 15:24
00055a8 to
d8fd968
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up on a minor pre-existing issue discovered when reviewing #5042.
This patch avoids an extra
.to_string()allocation and a redundantinto_iter() -> collect() -> into_iter()round trip.