diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2021-09-01 13:39:48 +0200 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2021-09-08 18:25:47 +0200 |
| commit | d7ef0b30e89960aede88bf450e4a2172332432e0 (patch) | |
| tree | 77c588a1157843b4b50bb60a96b16bc99f4faec5 | |
| parent | 58000ed0e9152e331dc7c7319c7783cc7f028f84 (diff) | |
| download | rust-d7ef0b30e89960aede88bf450e4a2172332432e0.tar.gz rust-d7ef0b30e89960aede88bf450e4a2172332432e0.zip | |
Use Lrc instead of Option to avoid duplication of a SearchPath
| -rw-r--r-- | compiler/rustc_driver/src/lib.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_session/src/session.rs | 16 |
2 files changed, 9 insertions, 12 deletions
diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 53053327d0d..4c6a2baaef1 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -677,10 +677,7 @@ impl RustcDefaultCalls { println!("{}", targets.join("\n")); } Sysroot => println!("{}", sess.sysroot.display()), - TargetLibdir => println!( - "{}", - sess.target_tlib_path.as_ref().unwrap_or(&sess.host_tlib_path).dir.display() - ), + TargetLibdir => println!("{}", sess.target_tlib_path.dir.display()), TargetSpec => println!("{}", sess.target.to_json().pretty()), FileNames | CrateName => { let input = input.unwrap_or_else(|| { diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 648743b7e86..58ea29c080f 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -131,9 +131,8 @@ pub struct Session { pub target: Target, pub host: Target, pub opts: config::Options, - pub host_tlib_path: SearchPath, - /// `None` if the host and target are the same. - pub target_tlib_path: Option<SearchPath>, + pub host_tlib_path: Lrc<SearchPath>, + pub target_tlib_path: Lrc<SearchPath>, pub parse_sess: ParseSess, pub sysroot: PathBuf, /// The name of the root source file of the crate, in the local file system. @@ -784,8 +783,7 @@ impl Session { &self.sysroot, self.opts.target_triple.triple(), &self.opts.search_paths, - // `target_tlib_path == None` means it's the same as `host_tlib_path`. - self.target_tlib_path.as_ref().unwrap_or(&self.host_tlib_path), + &self.target_tlib_path, kind, ) } @@ -1254,11 +1252,13 @@ pub fn build_session( let host_triple = config::host_triple(); let target_triple = sopts.target_triple.triple(); - let host_tlib_path = SearchPath::from_sysroot_and_triple(&sysroot, host_triple); + let host_tlib_path = Lrc::new(SearchPath::from_sysroot_and_triple(&sysroot, host_triple)); let target_tlib_path = if host_triple == target_triple { - None + // Use the same `SearchPath` if host and target triple are identical to avoid unnecessary + // rescanning of the target lib path and an unnecessary allocation. + host_tlib_path.clone() } else { - Some(SearchPath::from_sysroot_and_triple(&sysroot, target_triple)) + Lrc::new(SearchPath::from_sysroot_and_triple(&sysroot, target_triple)) }; let file_path_mapping = sopts.file_path_mapping(); |
