Skip to content

Commit

Permalink
rustdoc: create rustc command with an iterator
Browse files Browse the repository at this point in the history
This avoids unnecessary allocation with a temporary Vec.
  • Loading branch information
tmfink committed Aug 21, 2023
1 parent 5e935ad commit f60a889
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,14 @@ fn add_exe_suffix(input: String, target: &TargetTriple) -> String {
}

fn wrapped_rustc_command(rustc_wrappers: &[PathBuf], rustc_binary: &Path) -> Command {
let args: Vec<&Path> =
rustc_wrappers.iter().map(PathBuf::as_path).chain([rustc_binary].into_iter()).collect();
let (exe, args) = args.split_first().expect("unable to create rustc command");
let mut args = rustc_wrappers.iter().map(PathBuf::as_path).chain([rustc_binary].into_iter());

let exe = args.next().expect("unable to create rustc command");
let mut command = Command::new(exe);
command.args(args);
for arg in args {
command.arg(arg);
}

command
}

Expand Down

0 comments on commit f60a889

Please sign in to comment.