@@ -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