Skip to content

Commit 7dbdb29

Browse files
committed
Remove unnecessary Arc from FilesIndex
1 parent f02672c commit 7dbdb29

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

compiler/rustc_session/src/search_paths.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct SearchPath {
1616

1717
/// [FilesIndex] contains paths that can be efficiently looked up with (prefix, suffix) pairs.
1818
#[derive(Clone, Debug)]
19-
pub struct FilesIndex(Vec<(Arc<str>, SearchPathFile)>);
19+
pub struct FilesIndex(Vec<SearchPathFile>);
2020

2121
impl FilesIndex {
2222
/// Look up [SearchPathFile] by (prefix, suffix) pair.
@@ -25,15 +25,15 @@ impl FilesIndex {
2525
prefix: &str,
2626
suffix: &str,
2727
) -> Option<impl Iterator<Item = (String, &'s SearchPathFile)>> {
28-
let start = self.0.partition_point(|(k, _)| **k < *prefix);
28+
let start = self.0.partition_point(|v| *v.file_name_str < *prefix);
2929
if start == self.0.len() {
3030
return None;
3131
}
32-
let end = self.0[start..].partition_point(|(k, _)| k.starts_with(prefix));
32+
let end = self.0[start..].partition_point(|v| v.file_name_str.starts_with(prefix));
3333
let prefixed_items = &self.0[start..][..end];
3434

35-
let ret = prefixed_items.into_iter().filter_map(move |(k, v)| {
36-
k.ends_with(suffix).then(|| {
35+
let ret = prefixed_items.into_iter().filter_map(move |v| {
36+
v.file_name_str.ends_with(suffix).then(|| {
3737
(
3838
String::from(
3939
&v.file_name_str[prefix.len()..v.file_name_str.len() - suffix.len()],
@@ -45,7 +45,7 @@ impl FilesIndex {
4545
Some(ret)
4646
}
4747
pub fn retain(&mut self, prefixes: &[&str]) {
48-
self.0.retain(|(k, _)| prefixes.iter().any(|prefix| k.starts_with(prefix)));
48+
self.0.retain(|v| prefixes.iter().any(|prefix| v.file_name_str.starts_with(prefix)));
4949
}
5050
}
5151
/// The obvious implementation of `SearchPath::files` is a `Vec<PathBuf>`. But
@@ -136,18 +136,15 @@ impl SearchPath {
136136
e.ok().and_then(|e| {
137137
e.file_name().to_str().map(|s| {
138138
let file_name_str: Arc<str> = s.into();
139-
(
140-
Arc::clone(&file_name_str),
141-
SearchPathFile { path: e.path().into(), file_name_str },
142-
)
139+
SearchPathFile { path: e.path().into(), file_name_str }
143140
})
144141
})
145142
})
146143
.collect::<Vec<_>>(),
147144

148145
Err(..) => Default::default(),
149146
};
150-
files.sort_by(|(lhs, _), (rhs, _)| lhs.cmp(rhs));
147+
files.sort_by(|lhs, rhs| lhs.file_name_str.cmp(&rhs.file_name_str));
151148
let files = FilesIndex(files);
152149
SearchPath { kind, dir, files }
153150
}

0 commit comments

Comments
 (0)