@@ -8,8 +8,8 @@ use crate::ich::Fingerprint;
8
8
use crate :: middle:: cstore:: CrateStore ;
9
9
use crate :: session:: CrateDisambiguator ;
10
10
use crate :: session:: Session ;
11
- use std :: iter :: repeat ;
12
- use syntax:: ast:: { NodeId , CRATE_NODE_ID } ;
11
+ use crate :: util :: nodemap :: FxHashMap ;
12
+ use syntax:: ast:: NodeId ;
13
13
use syntax:: source_map:: SourceMap ;
14
14
use syntax_pos:: Span ;
15
15
@@ -25,7 +25,7 @@ pub(super) struct NodeCollector<'a, 'hir> {
25
25
source_map : & ' a SourceMap ,
26
26
27
27
/// The node map
28
- map : Vec < Option < Entry < ' hir > > > ,
28
+ map : FxHashMap < HirId , Entry < ' hir > > ,
29
29
/// The parent of this node
30
30
parent_node : hir:: HirId ,
31
31
@@ -145,7 +145,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
145
145
let mut collector = NodeCollector {
146
146
krate,
147
147
source_map : sess. source_map ( ) ,
148
- map : repeat ( None ) . take ( sess. current_node_id_count ( ) ) . collect ( ) ,
148
+ map : FxHashMap :: with_capacity_and_hasher ( sess. current_node_id_count ( ) ,
149
+ Default :: default ( ) ) ,
149
150
parent_node : hir:: CRATE_HIR_ID ,
150
151
current_signature_dep_index : root_mod_sig_dep_index,
151
152
current_full_dep_index : root_mod_full_dep_index,
@@ -157,9 +158,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
157
158
hcx,
158
159
hir_body_nodes,
159
160
} ;
160
- collector. insert_entry ( CRATE_NODE_ID , Entry {
161
- parent : CRATE_NODE_ID ,
162
- parent_hir : hir:: CRATE_HIR_ID ,
161
+ collector. insert_entry ( hir:: CRATE_HIR_ID , Entry {
162
+ parent : hir:: CRATE_HIR_ID ,
163
163
dep_node : root_mod_sig_dep_index,
164
164
node : Node :: Crate ,
165
165
} ) ;
@@ -171,7 +171,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
171
171
crate_disambiguator : CrateDisambiguator ,
172
172
cstore : & dyn CrateStore ,
173
173
commandline_args_hash : u64 )
174
- -> ( Vec < Option < Entry < ' hir > > > , Svh )
174
+ -> ( FxHashMap < HirId , Entry < ' hir > > , Svh )
175
175
{
176
176
self . hir_body_nodes . sort_unstable_by_key ( |bn| bn. 0 ) ;
177
177
@@ -222,15 +222,14 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
222
222
( self . map , svh)
223
223
}
224
224
225
- fn insert_entry ( & mut self , id : NodeId , entry : Entry < ' hir > ) {
225
+ fn insert_entry ( & mut self , id : HirId , entry : Entry < ' hir > ) {
226
226
debug ! ( "hir_map: {:?} => {:?}" , id, entry) ;
227
- self . map [ id . as_usize ( ) ] = Some ( entry) ;
227
+ self . map . insert ( id , entry) ;
228
228
}
229
229
230
230
fn insert ( & mut self , span : Span , hir_id : HirId , node : Node < ' hir > ) {
231
231
let entry = Entry {
232
- parent : self . hir_to_node_id [ & self . parent_node ] ,
233
- parent_hir : self . parent_node ,
232
+ parent : self . parent_node ,
234
233
dep_node : if self . currently_in_body {
235
234
self . current_full_dep_index
236
235
} else {
@@ -239,12 +238,11 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
239
238
node,
240
239
} ;
241
240
242
- let node_id = self . hir_to_node_id [ & hir_id] ;
243
-
244
241
// Make sure that the DepNode of some node coincides with the HirId
245
242
// owner of that node.
246
243
if cfg ! ( debug_assertions) {
247
- assert_eq ! ( self . definitions. node_to_hir_id( node_id) , hir_id) ;
244
+ let node_id = self . hir_to_node_id [ & hir_id] ;
245
+ assert_eq ! ( self . definitions. node_to_hir_id( node_id) , hir_id) ;
248
246
249
247
if hir_id. owner != self . current_dep_node_owner {
250
248
let node_str = match self . definitions . opt_def_index ( node_id) {
@@ -277,7 +275,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
277
275
}
278
276
}
279
277
280
- self . insert_entry ( node_id , entry) ;
278
+ self . insert_entry ( hir_id , entry) ;
281
279
}
282
280
283
281
fn with_parent < F : FnOnce ( & mut Self ) > (
0 commit comments