Skip to content

Commit bff4c9a

Browse files
committed
Remove a sorting operation from used_crates
1 parent b342215 commit bff4c9a

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

compiler/rustc_middle/src/middle/cstore.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,23 +207,19 @@ pub type CrateStoreDyn = dyn CrateStore + sync::Sync;
207207
// around. For more info, see some comments in the add_used_library function
208208
// below.
209209
//
210-
// In order to get this left-to-right dependency ordering, we perform a
211-
// topological sort of all crates putting the leaves at the right-most
212-
// positions.
210+
// In order to get this left-to-right dependency ordering, we use the reverse
211+
// postorder of all crates putting the leaves at the right-most positions.
213212
pub fn used_crates(tcx: TyCtxt<'_>) -> Vec<CrateNum> {
214-
let mut libs = tcx
215-
.crates(())
213+
tcx
214+
.postorder_cnums(())
216215
.iter()
216+
.rev()
217217
.cloned()
218218
.filter_map(|cnum| {
219219
if tcx.dep_kind(cnum).macros_only() {
220220
return None;
221221
}
222222
Some(cnum)
223223
})
224-
.collect::<Vec<_>>();
225-
let mut ordering = tcx.postorder_cnums(()).to_owned();
226-
ordering.reverse();
227-
libs.sort_by_cached_key(|&a| ordering.iter().position(|x| *x == a));
228-
libs
224+
.collect::<Vec<_>>()
229225
}

0 commit comments

Comments
 (0)