Skip to content

Commit

Permalink
Remove unnecessary clone()s in bootstrap
Browse files Browse the repository at this point in the history
The performance difference is negligible, but it makes me feel better.

Note that this does not remove some clones in `config`, because it would
require changing the logic around (and performance doesn't matter
for bootstrap).
  • Loading branch information
jyn514 committed Sep 16, 2020
1 parent 5fae569 commit d04ca00
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ impl<'a> Builder<'a> {
cargo.env(format!("CC_{}", target.triple), &cc);

let cflags = self.cflags(target, GitRepo::Rustc).join(" ");
cargo.env(format!("CFLAGS_{}", target.triple), cflags.clone());
cargo.env(format!("CFLAGS_{}", target.triple), &cflags);

if let Some(ar) = self.ar(target) {
let ranlib = format!("{} s", ar.display());
Expand Down
65 changes: 33 additions & 32 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ impl Config {

pub fn parse(args: &[String]) -> Config {
let flags = Flags::parse(&args);

let mut config = Config::default_opts();
config.exclude = flags.exclude;
config.rustc_error_format = flags.rustc_error_format;
Expand Down Expand Up @@ -551,14 +552,14 @@ impl Config {
let has_targets = build.target.is_some() || flags.target.is_some();
config.skip_only_host_steps = !has_hosts && has_targets;

config.hosts = if let Some(arg_host) = flags.host.clone() {
config.hosts = if let Some(arg_host) = flags.host {
arg_host
} else if let Some(file_host) = build.host {
file_host.iter().map(|h| TargetSelection::from_user(h)).collect()
} else {
vec![config.build]
};
config.targets = if let Some(arg_target) = flags.target.clone() {
config.targets = if let Some(arg_target) = flags.target {
arg_target
} else if let Some(file_target) = build.target {
file_target.iter().map(|h| TargetSelection::from_user(h)).collect()
Expand Down Expand Up @@ -628,14 +629,14 @@ impl Config {

config.verbose = cmp::max(config.verbose, flags.verbose);

if let Some(ref install) = toml.install {
config.prefix = install.prefix.clone().map(PathBuf::from);
config.sysconfdir = install.sysconfdir.clone().map(PathBuf::from);
config.datadir = install.datadir.clone().map(PathBuf::from);
config.docdir = install.docdir.clone().map(PathBuf::from);
set(&mut config.bindir, install.bindir.clone().map(PathBuf::from));
config.libdir = install.libdir.clone().map(PathBuf::from);
config.mandir = install.mandir.clone().map(PathBuf::from);
if let Some(install) = toml.install {
config.prefix = install.prefix.map(PathBuf::from);
config.sysconfdir = install.sysconfdir.map(PathBuf::from);
config.datadir = install.datadir.map(PathBuf::from);
config.docdir = install.docdir.map(PathBuf::from);
set(&mut config.bindir, install.bindir.map(PathBuf::from));
config.libdir = install.libdir.map(PathBuf::from);
config.mandir = install.mandir.map(PathBuf::from);
}

// We want the llvm-skip-rebuild flag to take precedence over the
Expand All @@ -658,7 +659,7 @@ impl Config {
let mut optimize = None;
let mut ignore_git = None;

if let Some(ref llvm) = toml.llvm {
if let Some(llvm) = toml.llvm {
match llvm.ccache {
Some(StringOrBool::String(ref s)) => config.ccache = Some(s.to_string()),
Some(StringOrBool::Bool(true)) => {
Expand Down Expand Up @@ -726,7 +727,7 @@ impl Config {
}
}

if let Some(ref rust) = toml.rust {
if let Some(rust) = toml.rust {
debug = rust.debug;
debug_assertions = rust.debug_assertions;
debug_assertions_std = rust.debug_assertions_std;
Expand All @@ -746,7 +747,7 @@ impl Config {
set(&mut config.test_compare_mode, rust.test_compare_mode);
set(&mut config.llvm_libunwind, rust.llvm_libunwind);
set(&mut config.backtrace, rust.backtrace);
set(&mut config.channel, rust.channel.clone());
set(&mut config.channel, rust.channel);
set(&mut config.rust_dist_src, rust.dist_src);
set(&mut config.verbose_tests, rust.verbose_tests);
// in the case "false" is set explicitly, do not overwrite the command line args
Expand All @@ -757,9 +758,9 @@ impl Config {
set(&mut config.lld_enabled, rust.lld);
set(&mut config.llvm_tools_enabled, rust.llvm_tools);
config.rustc_parallel = rust.parallel_compiler.unwrap_or(false);
config.rustc_default_linker = rust.default_linker.clone();
config.musl_root = rust.musl_root.clone().map(PathBuf::from);
config.save_toolstates = rust.save_toolstates.clone().map(PathBuf::from);
config.rustc_default_linker = rust.default_linker;
config.musl_root = rust.musl_root.map(PathBuf::from);
config.save_toolstates = rust.save_toolstates.map(PathBuf::from);
set(&mut config.deny_warnings, flags.deny_warnings.or(rust.deny_warnings));
set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
set(&mut config.rust_verify_llvm_ir, rust.verify_llvm_ir);
Expand All @@ -776,9 +777,9 @@ impl Config {
config.rust_codegen_units_std = rust.codegen_units_std.map(threads_from_config);
}

if let Some(ref t) = toml.target {
if let Some(t) = toml.target {
for (triple, cfg) in t {
let mut target = Target::from_triple(triple);
let mut target = Target::from_triple(&triple);

if let Some(ref s) = cfg.llvm_config {
target.llvm_config = Some(config.src.join(s));
Expand All @@ -792,18 +793,18 @@ impl Config {
if let Some(s) = cfg.no_std {
target.no_std = s;
}
target.cc = cfg.cc.clone().map(PathBuf::from);
target.cxx = cfg.cxx.clone().map(PathBuf::from);
target.ar = cfg.ar.clone().map(PathBuf::from);
target.ranlib = cfg.ranlib.clone().map(PathBuf::from);
target.linker = cfg.linker.clone().map(PathBuf::from);
target.cc = cfg.cc.map(PathBuf::from);
target.cxx = cfg.cxx.map(PathBuf::from);
target.ar = cfg.ar.map(PathBuf::from);
target.ranlib = cfg.ranlib.map(PathBuf::from);
target.linker = cfg.linker.map(PathBuf::from);
target.crt_static = cfg.crt_static;
target.musl_root = cfg.musl_root.clone().map(PathBuf::from);
target.musl_libdir = cfg.musl_libdir.clone().map(PathBuf::from);
target.wasi_root = cfg.wasi_root.clone().map(PathBuf::from);
target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from);
target.musl_root = cfg.musl_root.map(PathBuf::from);
target.musl_libdir = cfg.musl_libdir.map(PathBuf::from);
target.wasi_root = cfg.wasi_root.map(PathBuf::from);
target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from);

config.target_config.insert(TargetSelection::from_user(triple), target);
config.target_config.insert(TargetSelection::from_user(&triple), target);
}
}

Expand All @@ -821,10 +822,10 @@ impl Config {
build_target.llvm_filecheck = Some(ci_llvm_bin.join(exe("FileCheck", config.build)));
}

if let Some(ref t) = toml.dist {
config.dist_sign_folder = t.sign_folder.clone().map(PathBuf::from);
config.dist_gpg_password_file = t.gpg_password_file.clone().map(PathBuf::from);
config.dist_upload_addr = t.upload_addr.clone();
if let Some(t) = toml.dist {
config.dist_sign_folder = t.sign_folder.map(PathBuf::from);
config.dist_gpg_password_file = t.gpg_password_file.map(PathBuf::from);
config.dist_upload_addr = t.upload_addr;
set(&mut config.rust_dist_src, t.src_tarball);
set(&mut config.missing_tools, t.missing_tools);
}
Expand Down
8 changes: 3 additions & 5 deletions src/bootstrap/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,13 @@ pub fn format(build: &Build, check: bool) {
eprintln!("./x.py fmt is not supported on this channel");
std::process::exit(1);
});
let src = build.src.clone();
let walker = WalkBuilder::new(&build.src).types(matcher).overrides(ignore_fmt).build_parallel();
let src = &build.src;
let walker = WalkBuilder::new(src).types(matcher).overrides(ignore_fmt).build_parallel();
walker.run(|| {
let src = src.clone();
let rustfmt_path = rustfmt_path.clone();
Box::new(move |entry| {
let entry = t!(entry);
if entry.file_type().map_or(false, |t| t.is_file()) {
rustfmt(&src, &rustfmt_path, &entry.path(), check);
rustfmt(src, &rustfmt_path, &entry.path(), check);
}
ignore::WalkState::Continue
})
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ impl Finder {
Self { cache: HashMap::new(), path: env::var_os("PATH").unwrap_or_default() }
}

pub fn maybe_have<S: AsRef<OsStr>>(&mut self, cmd: S) -> Option<PathBuf> {
let cmd: OsString = cmd.as_ref().into();
pub fn maybe_have<S: Into<OsString>>(&mut self, cmd: S) -> Option<PathBuf> {
let cmd: OsString = cmd.into();
let path = &self.path;
self.cache
.entry(cmd.clone())
Expand Down

0 comments on commit d04ca00

Please sign in to comment.