@@ -18,7 +18,7 @@ use hir;
18
18
use hir:: def_id:: { CrateNum , DefId , DefIndex , LOCAL_CRATE , DefIndexAddressSpace ,
19
19
CRATE_DEF_INDEX } ;
20
20
use ich:: Fingerprint ;
21
- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
21
+ use rustc_data_structures:: fx:: FxHashMap ;
22
22
use rustc_data_structures:: indexed_vec:: IndexVec ;
23
23
use rustc_data_structures:: stable_hasher:: StableHasher ;
24
24
use serialize:: { Encodable , Decodable , Encoder , Decoder } ;
@@ -153,7 +153,7 @@ pub struct Definitions {
153
153
pub ( super ) node_to_hir_id : IndexVec < ast:: NodeId , hir:: HirId > ,
154
154
macro_def_scopes : FxHashMap < Mark , DefId > ,
155
155
expansions : FxHashMap < DefIndex , Mark > ,
156
- keys_created : FxHashSet < DefKey > ,
156
+ next_disambiguator : FxHashMap < ( DefIndex , DefPathData ) , u32 > ,
157
157
}
158
158
159
159
// Unfortunately we have to provide a manual impl of Clone because of the
@@ -170,7 +170,7 @@ impl Clone for Definitions {
170
170
node_to_hir_id : self . node_to_hir_id . clone ( ) ,
171
171
macro_def_scopes : self . macro_def_scopes . clone ( ) ,
172
172
expansions : self . expansions . clone ( ) ,
173
- keys_created : self . keys_created . clone ( ) ,
173
+ next_disambiguator : self . next_disambiguator . clone ( ) ,
174
174
}
175
175
}
176
176
}
@@ -402,7 +402,7 @@ impl Definitions {
402
402
node_to_hir_id : IndexVec :: new ( ) ,
403
403
macro_def_scopes : FxHashMap ( ) ,
404
404
expansions : FxHashMap ( ) ,
405
- keys_created : FxHashSet ( ) ,
405
+ next_disambiguator : FxHashMap ( ) ,
406
406
}
407
407
}
408
408
@@ -516,21 +516,21 @@ impl Definitions {
516
516
// The root node must be created with create_root_def()
517
517
assert ! ( data != DefPathData :: CrateRoot ) ;
518
518
519
- // Find a unique DefKey. This basically means incrementing the disambiguator
520
- // until we get no match.
521
- let mut key = DefKey {
519
+ // Find the next free disambiguator for this key.
520
+ let disambiguator = {
521
+ let next_disamb = self . next_disambiguator . entry ( ( parent, data. clone ( ) ) ) . or_insert ( 0 ) ;
522
+ let disambiguator = * next_disamb;
523
+ * next_disamb = next_disamb. checked_add ( 1 ) . expect ( "disambiguator overflow" ) ;
524
+ disambiguator
525
+ } ;
526
+
527
+ let key = DefKey {
522
528
parent : Some ( parent) ,
523
529
disambiguated_data : DisambiguatedDefPathData {
524
- data,
525
- disambiguator : 0
530
+ data, disambiguator
526
531
}
527
532
} ;
528
533
529
- while self . keys_created . contains ( & key) {
530
- key. disambiguated_data . disambiguator += 1 ;
531
- }
532
- self . keys_created . insert ( key. clone ( ) ) ;
533
-
534
534
let parent_hash = self . table . def_path_hash ( parent) ;
535
535
let def_path_hash = key. compute_stable_hash ( parent_hash) ;
536
536
0 commit comments