@@ -195,7 +195,6 @@ use rustc_session::lint::builtin::LARGE_ASSIGNMENTS;
195195use rustc_session:: Limit ;
196196use rustc_span:: source_map:: { dummy_spanned, respan, Span , Spanned , DUMMY_SP } ;
197197use rustc_target:: abi:: Size ;
198- use std:: ops:: Range ;
199198use std:: path:: PathBuf ;
200199
201200use crate :: errors:: {
@@ -209,27 +208,18 @@ pub enum MonoItemCollectionMode {
209208}
210209
211210pub 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 > > > ,
215213
216214 // Maps every mono item to the mono items that use it.
217215 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 > > ,
222216}
223217
224218type MonoItems < ' tcx > = Vec < Spanned < MonoItem < ' tcx > > > ;
225219
226220impl < ' tcx > UsageMap < ' tcx > {
227221 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 ( ) }
233223 }
234224
235225 fn record_used < ' a > (
@@ -239,18 +229,12 @@ impl<'tcx> UsageMap<'tcx> {
239229 ) where
240230 ' tcx : ' a ,
241231 {
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) ;
251235 }
252236
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( ) ) ;
254238 }
255239
256240 pub fn get_user_items ( & self , item : MonoItem < ' tcx > ) -> Option < & [ MonoItem < ' tcx > ] > {
@@ -262,12 +246,11 @@ impl<'tcx> UsageMap<'tcx> {
262246 where
263247 F : FnMut ( MonoItem < ' tcx > ) ,
264248 {
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) ;
271254 }
272255 }
273256 }
0 commit comments