@@ -1309,7 +1309,7 @@ impl HygieneEncodeContext {
1309
1309
pub struct HygieneDecodeContext {
1310
1310
// A cache mapping raw serialized per-crate syntax context ids to corresponding decoded
1311
1311
// `SyntaxContext`s in the current global `HygieneData`.
1312
- remapped_ctxts : Lock < Vec < Option < SyntaxContext > > > ,
1312
+ remapped_ctxts : Lock < IndexVec < u32 , Option < SyntaxContext > > > ,
1313
1313
}
1314
1314
1315
1315
/// Register an expansion which has been decoded from the on-disk-cache for the local crate.
@@ -1395,8 +1395,8 @@ pub fn decode_syntax_context<D: Decoder>(
1395
1395
// Look into the cache first.
1396
1396
// Reminder: `HygieneDecodeContext` is per-crate, so there are no collisions between
1397
1397
// raw ids from different crate metadatas.
1398
- if let Some ( ctxt) = context. remapped_ctxts . lock ( ) . get ( raw_id as usize ) . copied ( ) . flatten ( ) {
1399
- return ctxt;
1398
+ if let Some ( Some ( ctxt) ) = context. remapped_ctxts . lock ( ) . get ( raw_id) {
1399
+ return * ctxt;
1400
1400
}
1401
1401
1402
1402
// Don't try to decode data while holding the lock, since we need to
@@ -1405,12 +1405,7 @@ pub fn decode_syntax_context<D: Decoder>(
1405
1405
let ctxt =
1406
1406
HygieneData :: with ( |hygiene_data| hygiene_data. alloc_ctxt ( parent, expn_id, transparency) ) ;
1407
1407
1408
- let mut remapped_ctxts = context. remapped_ctxts . lock ( ) ;
1409
- let new_len = raw_id as usize + 1 ;
1410
- if remapped_ctxts. len ( ) < new_len {
1411
- remapped_ctxts. resize ( new_len, None ) ;
1412
- }
1413
- remapped_ctxts[ raw_id as usize ] = Some ( ctxt) ;
1408
+ context. remapped_ctxts . lock ( ) . insert ( raw_id, ctxt) ;
1414
1409
1415
1410
ctxt
1416
1411
}
0 commit comments