Skip to content

Commit d7ef0b3

Browse files
committed
Use Lrc instead of Option to avoid duplication of a SearchPath
1 parent 58000ed commit d7ef0b3

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

compiler/rustc_driver/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,7 @@ impl RustcDefaultCalls {
677677
println!("{}", targets.join("\n"));
678678
}
679679
Sysroot => println!("{}", sess.sysroot.display()),
680-
TargetLibdir => println!(
681-
"{}",
682-
sess.target_tlib_path.as_ref().unwrap_or(&sess.host_tlib_path).dir.display()
683-
),
680+
TargetLibdir => println!("{}", sess.target_tlib_path.dir.display()),
684681
TargetSpec => println!("{}", sess.target.to_json().pretty()),
685682
FileNames | CrateName => {
686683
let input = input.unwrap_or_else(|| {

compiler/rustc_session/src/session.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ pub struct Session {
131131
pub target: Target,
132132
pub host: Target,
133133
pub opts: config::Options,
134-
pub host_tlib_path: SearchPath,
135-
/// `None` if the host and target are the same.
136-
pub target_tlib_path: Option<SearchPath>,
134+
pub host_tlib_path: Lrc<SearchPath>,
135+
pub target_tlib_path: Lrc<SearchPath>,
137136
pub parse_sess: ParseSess,
138137
pub sysroot: PathBuf,
139138
/// The name of the root source file of the crate, in the local file system.
@@ -784,8 +783,7 @@ impl Session {
784783
&self.sysroot,
785784
self.opts.target_triple.triple(),
786785
&self.opts.search_paths,
787-
// `target_tlib_path == None` means it's the same as `host_tlib_path`.
788-
self.target_tlib_path.as_ref().unwrap_or(&self.host_tlib_path),
786+
&self.target_tlib_path,
789787
kind,
790788
)
791789
}
@@ -1254,11 +1252,13 @@ pub fn build_session(
12541252

12551253
let host_triple = config::host_triple();
12561254
let target_triple = sopts.target_triple.triple();
1257-
let host_tlib_path = SearchPath::from_sysroot_and_triple(&sysroot, host_triple);
1255+
let host_tlib_path = Lrc::new(SearchPath::from_sysroot_and_triple(&sysroot, host_triple));
12581256
let target_tlib_path = if host_triple == target_triple {
1259-
None
1257+
// Use the same `SearchPath` if host and target triple are identical to avoid unnecessary
1258+
// rescanning of the target lib path and an unnecessary allocation.
1259+
host_tlib_path.clone()
12601260
} else {
1261-
Some(SearchPath::from_sysroot_and_triple(&sysroot, target_triple))
1261+
Lrc::new(SearchPath::from_sysroot_and_triple(&sysroot, target_triple))
12621262
};
12631263

12641264
let file_path_mapping = sopts.file_path_mapping();

0 commit comments

Comments
 (0)