@@ -131,9 +131,8 @@ pub struct Session {
131
131
pub target : Target ,
132
132
pub host : Target ,
133
133
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 > ,
137
136
pub parse_sess : ParseSess ,
138
137
pub sysroot : PathBuf ,
139
138
/// The name of the root source file of the crate, in the local file system.
@@ -784,8 +783,7 @@ impl Session {
784
783
& self . sysroot ,
785
784
self . opts . target_triple . triple ( ) ,
786
785
& 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 ,
789
787
kind,
790
788
)
791
789
}
@@ -1254,11 +1252,13 @@ pub fn build_session(
1254
1252
1255
1253
let host_triple = config:: host_triple ( ) ;
1256
1254
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) ) ;
1258
1256
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 ( )
1260
1260
} else {
1261
- Some ( SearchPath :: from_sysroot_and_triple ( & sysroot, target_triple) )
1261
+ Lrc :: new ( SearchPath :: from_sysroot_and_triple ( & sysroot, target_triple) )
1262
1262
} ;
1263
1263
1264
1264
let file_path_mapping = sopts. file_path_mapping ( ) ;
0 commit comments