Skip to content

Commit 7148908

Browse files
committed
hygiene: Use IndexVec for syntax context decode cache
1 parent c7ad140 commit 7148908

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

compiler/rustc_span/src/hygiene.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ impl HygieneEncodeContext {
13091309
pub struct HygieneDecodeContext {
13101310
// A cache mapping raw serialized per-crate syntax context ids to corresponding decoded
13111311
// `SyntaxContext`s in the current global `HygieneData`.
1312-
remapped_ctxts: Lock<Vec<Option<SyntaxContext>>>,
1312+
remapped_ctxts: Lock<IndexVec<u32, Option<SyntaxContext>>>,
13131313
}
13141314

13151315
/// 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>(
13951395
// Look into the cache first.
13961396
// Reminder: `HygieneDecodeContext` is per-crate, so there are no collisions between
13971397
// 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;
14001400
}
14011401

14021402
// 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>(
14051405
let ctxt =
14061406
HygieneData::with(|hygiene_data| hygiene_data.alloc_ctxt(parent, expn_id, transparency));
14071407

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);
14141409

14151410
ctxt
14161411
}

0 commit comments

Comments
 (0)