@@ -195,7 +195,6 @@ use rustc_session::lint::builtin::LARGE_ASSIGNMENTS;
195
195
use rustc_session:: Limit ;
196
196
use rustc_span:: source_map:: { dummy_spanned, respan, Span , Spanned , DUMMY_SP } ;
197
197
use rustc_target:: abi:: Size ;
198
- use std:: ops:: Range ;
199
198
use std:: path:: PathBuf ;
200
199
201
200
use crate :: errors:: {
@@ -209,27 +208,18 @@ pub enum MonoItemCollectionMode {
209
208
}
210
209
211
210
pub struct UsageMap < ' tcx > {
212
- // Maps every mono item to the mono items used by it. Those mono items
213
- // are represented as a range, which indexes into `used_items`.
214
- used_map : FxHashMap < MonoItem < ' tcx > , Range < usize > > ,
211
+ // Maps every mono item to the mono items used by it.
212
+ used_map : FxHashMap < MonoItem < ' tcx > , Vec < MonoItem < ' tcx > > > ,
215
213
216
214
// Maps every mono item to the mono items that use it.
217
215
user_map : FxHashMap < MonoItem < ' tcx > , Vec < MonoItem < ' tcx > > > ,
218
-
219
- // A mono item that is used by N different other mono items will appear
220
- // here N times. Indexed into by the ranges in `used_map`.
221
- used_items : Vec < MonoItem < ' tcx > > ,
222
216
}
223
217
224
218
type MonoItems < ' tcx > = Vec < Spanned < MonoItem < ' tcx > > > ;
225
219
226
220
impl < ' tcx > UsageMap < ' tcx > {
227
221
fn new ( ) -> UsageMap < ' tcx > {
228
- UsageMap {
229
- used_map : FxHashMap :: default ( ) ,
230
- user_map : FxHashMap :: default ( ) ,
231
- used_items : Vec :: new ( ) ,
232
- }
222
+ UsageMap { used_map : FxHashMap :: default ( ) , user_map : FxHashMap :: default ( ) }
233
223
}
234
224
235
225
fn record_used < ' a > (
@@ -239,18 +229,12 @@ impl<'tcx> UsageMap<'tcx> {
239
229
) where
240
230
' tcx : ' a ,
241
231
{
242
- let old_len = self . used_items . len ( ) ;
243
- let new_len = old_len + used_items. len ( ) ;
244
- let new_items_range = old_len..new_len;
245
-
246
- self . used_items . reserve ( used_items. len ( ) ) ;
247
-
248
- for Spanned { node : used_item, .. } in used_items. into_iter ( ) {
249
- self . used_items . push ( * used_item) ;
250
- self . user_map . entry ( * used_item) . or_default ( ) . push ( user_item) ;
232
+ let used_items: Vec < _ > = used_items. iter ( ) . map ( |item| item. node ) . collect ( ) ;
233
+ for & used_item in used_items. iter ( ) {
234
+ self . user_map . entry ( used_item) . or_default ( ) . push ( user_item) ;
251
235
}
252
236
253
- assert ! ( self . used_map. insert( user_item, new_items_range ) . is_none( ) ) ;
237
+ assert ! ( self . used_map. insert( user_item, used_items ) . is_none( ) ) ;
254
238
}
255
239
256
240
pub fn get_user_items ( & self , item : MonoItem < ' tcx > ) -> Option < & [ MonoItem < ' tcx > ] > {
@@ -262,12 +246,11 @@ impl<'tcx> UsageMap<'tcx> {
262
246
where
263
247
F : FnMut ( MonoItem < ' tcx > ) ,
264
248
{
265
- if let Some ( range) = self . used_map . get ( & item) {
266
- for used_item in self . used_items [ range. clone ( ) ] . iter ( ) {
267
- let is_inlined = used_item. instantiation_mode ( tcx) == InstantiationMode :: LocalCopy ;
268
- if is_inlined {
269
- f ( * used_item) ;
270
- }
249
+ let used_items = self . used_map . get ( & item) . unwrap ( ) ;
250
+ for used_item in used_items. iter ( ) {
251
+ let is_inlined = used_item. instantiation_mode ( tcx) == InstantiationMode :: LocalCopy ;
252
+ if is_inlined {
253
+ f ( * used_item) ;
271
254
}
272
255
}
273
256
}
0 commit comments