@@ -96,29 +96,27 @@ pub struct CStore {
9696impl CStore {
9797 pub fn new ( metadata_loader : Box < MetadataLoader + Sync > ) -> CStore {
9898 CStore {
99- metas : RwLock :: new ( IndexVec :: new ( ) ) ,
99+ metas : RwLock :: new ( IndexVec :: from_elem_n ( None , 1 ) ) ,
100100 extern_mod_crate_map : Lock :: new ( FxHashMap ( ) ) ,
101101 metadata_loader,
102102 }
103103 }
104104
105- /// You cannot use this function to allocate a CrateNum in a thread-safe manner.
106- /// It is currently only used in CrateLoader which is single-threaded code.
107- pub ( super ) fn next_crate_num ( & self ) -> CrateNum {
108- CrateNum :: new ( self . metas . borrow ( ) . len ( ) + 1 )
105+ pub ( super ) fn alloc_new_crate_num ( & self ) -> CrateNum {
106+ let mut metas = self . metas . borrow_mut ( ) ;
107+ let cnum = CrateNum :: new ( metas. len ( ) ) ;
108+ metas. push ( None ) ;
109+ cnum
109110 }
110111
111112 pub ( super ) fn get_crate_data ( & self , cnum : CrateNum ) -> Lrc < CrateMetadata > {
112113 self . metas . borrow ( ) [ cnum] . clone ( ) . unwrap ( )
113114 }
114115
115116 pub ( super ) fn set_crate_data ( & self , cnum : CrateNum , data : Lrc < CrateMetadata > ) {
116- use rustc_data_structures:: indexed_vec:: Idx ;
117- let mut met = self . metas . borrow_mut ( ) ;
118- while met. len ( ) <= cnum. index ( ) {
119- met. push ( None ) ;
120- }
121- met[ cnum] = Some ( data) ;
117+ let mut metas = self . metas . borrow_mut ( ) ;
118+ assert ! ( metas[ cnum] . is_none( ) , "Overwriting crate metadata entry" ) ;
119+ metas[ cnum] = Some ( data) ;
122120 }
123121
124122 pub ( super ) fn iter_crate_data < I > ( & self , mut i : I )
0 commit comments