File tree 2 files changed +7
-11
lines changed 2 files changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -490,26 +490,24 @@ impl CrateGraph {
490
490
}
491
491
}
492
492
493
- pub fn sort_deps ( & mut self ) {
494
- self . arena
495
- . iter_mut ( )
496
- . for_each ( |( _, data) | data. dependencies . sort_by_key ( |dep| dep. crate_id ) ) ;
497
- }
498
-
499
493
/// Extends this crate graph by adding a complete second crate
500
494
/// graph and adjust the ids in the [`ProcMacroPaths`] accordingly.
501
495
///
502
496
/// This will deduplicate the crates of the graph where possible.
503
- /// Note that for deduplication to fully work, `self`'s crate dependencies must be sorted by crate id.
504
- /// If the crate dependencies were sorted, the resulting graph from this `extend` call will also
505
- /// have the crate dependencies sorted.
497
+ /// Furthermore dependencies are sorted by crate id to make deduplication easier.
506
498
///
507
499
/// Returns a map mapping `other`'s IDs to the new IDs in `self`.
508
500
pub fn extend (
509
501
& mut self ,
510
502
mut other : CrateGraph ,
511
503
proc_macros : & mut ProcMacroPaths ,
512
504
) -> FxHashMap < CrateId , CrateId > {
505
+ // Sorting here is a bit pointless because the input is likely already sorted.
506
+ // However, the overhead is small and it makes the `extend` method harder to misuse.
507
+ self . arena
508
+ . iter_mut ( )
509
+ . for_each ( |( _, data) | data. dependencies . sort_by_key ( |dep| dep. crate_id ) ) ;
510
+
513
511
let m = self . len ( ) ;
514
512
let topo = other. crates_in_topological_order ( ) ;
515
513
let mut id_map: FxHashMap < CrateId , CrateId > = FxHashMap :: default ( ) ;
Original file line number Diff line number Diff line change @@ -232,7 +232,6 @@ fn rust_project_is_proc_macro_has_proc_macro_dep() {
232
232
#[ test]
233
233
fn crate_graph_dedup_identical ( ) {
234
234
let ( mut crate_graph, proc_macros) = load_cargo ( "regex-metadata.json" ) ;
235
- crate_graph. sort_deps ( ) ;
236
235
237
236
let ( d_crate_graph, mut d_proc_macros) = ( crate_graph. clone ( ) , proc_macros. clone ( ) ) ;
238
237
@@ -253,7 +252,6 @@ fn crate_graph_dedup() {
253
252
let ( regex_crate_graph, mut regex_proc_macros) = to_crate_graph ( regex_workspace, & mut file_map) ;
254
253
assert_eq ! ( regex_crate_graph. iter( ) . count( ) , 50 ) ;
255
254
256
- crate_graph. sort_deps ( ) ;
257
255
crate_graph. extend ( regex_crate_graph, & mut regex_proc_macros) ;
258
256
assert_eq ! ( crate_graph. iter( ) . count( ) , 108 ) ;
259
257
}
You can’t perform that action at this time.
0 commit comments