Inline and remove FileSearch::search.

It has only a single callsite, and having all the code in one place will
make it possible to optimize the search.
This commit is contained in:
Nicholas Nethercote 2022-02-01 16:32:13 +11:00
parent 47b5d95db8
commit 89b61ea09f
2 changed files with 47 additions and 49 deletions

View File

@ -394,16 +394,23 @@ fn find_library_crate(
// of the crate id (path/name/id).
//
// The goal of this step is to look at as little metadata as possible.
self.filesearch.search(|spf, kind| {
for search_path in self.filesearch.search_paths() {
debug!("searching {}", search_path.dir.display());
for spf in search_path.files.iter() {
debug!("testing {}", spf.path.display());
let file = match &spf.file_name_str {
None => return,
None => continue,
Some(file) => file,
};
let (hash, found_kind) = if file.starts_with(&rlib_prefix) && file.ends_with(".rlib") {
let (hash, found_kind) = if file.starts_with(&rlib_prefix)
&& file.ends_with(".rlib")
{
(&file[(rlib_prefix.len())..(file.len() - ".rlib".len())], CrateFlavor::Rlib)
} else if file.starts_with(&rlib_prefix) && file.ends_with(".rmeta") {
(&file[(rlib_prefix.len())..(file.len() - ".rmeta".len())], CrateFlavor::Rmeta)
} else if file.starts_with(&dylib_prefix) && file.ends_with(&self.target.dll_suffix) {
} else if file.starts_with(&dylib_prefix) && file.ends_with(&self.target.dll_suffix)
{
(
&file[(dylib_prefix.len())..(file.len() - self.target.dll_suffix.len())],
CrateFlavor::Dylib,
@ -412,10 +419,12 @@ fn find_library_crate(
if file.starts_with(&staticlib_prefix)
&& file.ends_with(&self.target.staticlib_suffix)
{
staticlibs
.push(CrateMismatch { path: spf.path.clone(), got: "static".to_string() });
staticlibs.push(CrateMismatch {
path: spf.path.clone(),
got: "static".to_string(),
});
}
return;
continue;
};
info!("lib candidate: {}", spf.path.display());
@ -423,15 +432,17 @@ fn find_library_crate(
let (rlibs, rmetas, dylibs) = candidates.entry(hash.to_string()).or_default();
let path = fs::canonicalize(&spf.path).unwrap_or_else(|_| spf.path.clone());
if seen_paths.contains(&path) {
return;
continue;
};
seen_paths.insert(path.clone());
match found_kind {
CrateFlavor::Rlib => rlibs.insert(path, kind),
CrateFlavor::Rmeta => rmetas.insert(path, kind),
CrateFlavor::Dylib => dylibs.insert(path, kind),
CrateFlavor::Rlib => rlibs.insert(path, search_path.kind),
CrateFlavor::Rmeta => rmetas.insert(path, search_path.kind),
CrateFlavor::Dylib => dylibs.insert(path, search_path.kind),
};
});
}
}
self.crate_rejections.via_kind.extend(staticlibs);
// We have now collected all known libraries into a set of candidates

View File

@ -5,7 +5,7 @@
use std::iter::FromIterator;
use std::path::{Path, PathBuf};
use crate::search_paths::{PathKind, SearchPath, SearchPathFile};
use crate::search_paths::{PathKind, SearchPath};
use rustc_fs_util::fix_windows_verbatim_for_gcc;
use tracing::debug;
@ -41,19 +41,6 @@ pub fn get_self_contained_lib_path(&self) -> PathBuf {
self.get_lib_path().join("self-contained")
}
pub fn search<F>(&self, mut pick: F)
where
F: FnMut(&SearchPathFile, PathKind),
{
for search_path in self.search_paths() {
debug!("searching {}", search_path.dir.display());
for spf in search_path.files.iter() {
debug!("testing {}", spf.path.display());
pick(spf, search_path.kind);
}
}
}
pub fn new(
sysroot: &'a Path,
triple: &'a str,