@@ -91,7 +91,7 @@ pub struct CrateMetadata {
91
91
}
92
92
93
93
pub struct CStore {
94
- metas : RefCell < FxHashMap < CrateNum , Rc < CrateMetadata > > > ,
94
+ metas : RefCell < IndexVec < CrateNum , Option < Rc < CrateMetadata > > > > ,
95
95
/// Map from NodeId's of local extern crate statements to crate numbers
96
96
extern_mod_crate_map : RefCell < NodeMap < CrateNum > > ,
97
97
pub metadata_loader : Box < MetadataLoader > ,
@@ -100,7 +100,7 @@ pub struct CStore {
100
100
impl CStore {
101
101
pub fn new ( metadata_loader : Box < MetadataLoader > ) -> CStore {
102
102
CStore {
103
- metas : RefCell :: new ( FxHashMap ( ) ) ,
103
+ metas : RefCell :: new ( IndexVec :: new ( ) ) ,
104
104
extern_mod_crate_map : RefCell :: new ( FxHashMap ( ) ) ,
105
105
metadata_loader,
106
106
}
@@ -111,18 +111,25 @@ impl CStore {
111
111
}
112
112
113
113
pub fn get_crate_data ( & self , cnum : CrateNum ) -> Rc < CrateMetadata > {
114
- self . metas . borrow ( ) . get ( & cnum) . unwrap ( ) . clone ( )
114
+ self . metas . borrow ( ) [ cnum] . clone ( ) . unwrap ( )
115
115
}
116
116
117
117
pub fn set_crate_data ( & self , cnum : CrateNum , data : Rc < CrateMetadata > ) {
118
- self . metas . borrow_mut ( ) . insert ( cnum, data) ;
118
+ use rustc_data_structures:: indexed_vec:: Idx ;
119
+ let mut met = self . metas . borrow_mut ( ) ;
120
+ while met. len ( ) <= cnum. index ( ) {
121
+ met. push ( None ) ;
122
+ }
123
+ met[ cnum] = Some ( data) ;
119
124
}
120
125
121
126
pub fn iter_crate_data < I > ( & self , mut i : I )
122
127
where I : FnMut ( CrateNum , & Rc < CrateMetadata > )
123
128
{
124
- for ( & k, v) in self . metas . borrow ( ) . iter ( ) {
125
- i ( k, v) ;
129
+ for ( k, v) in self . metas . borrow ( ) . iter_enumerated ( ) {
130
+ if let & Some ( ref v) = v {
131
+ i ( k, v) ;
132
+ }
126
133
}
127
134
}
128
135
@@ -150,8 +157,10 @@ impl CStore {
150
157
151
158
pub fn do_postorder_cnums_untracked ( & self ) -> Vec < CrateNum > {
152
159
let mut ordering = Vec :: new ( ) ;
153
- for ( & num, _) in self . metas . borrow ( ) . iter ( ) {
154
- self . push_dependencies_in_postorder ( & mut ordering, num) ;
160
+ for ( num, v) in self . metas . borrow ( ) . iter_enumerated ( ) {
161
+ if let & Some ( _) = v {
162
+ self . push_dependencies_in_postorder ( & mut ordering, num) ;
163
+ }
155
164
}
156
165
return ordering
157
166
}
0 commit comments