Skip to content

Commit 5f079dd

Browse files
committed
alloc id is indexmapped
1 parent 0f27c1b commit 5f079dd

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,13 @@ impl<'tcx> Tables<'tcx> {
107107

108108
fn create_alloc_id(&mut self, aid: AllocId) -> stable_mir::AllocId {
109109
// FIXME: this becomes inefficient when we have too many ids
110-
if let Some(i) = self.alloc_ids.iter().position(|a| *a == aid) {
111-
return stable_mir::AllocId(i);
112-
};
113-
let id = self.def_ids.len();
114-
self.alloc_ids.push(aid);
115-
stable_mir::AllocId(id)
110+
if let Some(i) = self.alloc_ids.get(&aid) {
111+
return *i;
112+
} else {
113+
let id = self.def_ids.len();
114+
self.alloc_ids.insert(aid, stable_mir::AllocId(id));
115+
stable_mir::AllocId(id)
116+
}
116117
}
117118

118119
pub(crate) fn create_span(&mut self, span: Span) -> stable_mir::ty::Span {
@@ -136,7 +137,7 @@ pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
136137
Tables {
137138
tcx,
138139
def_ids: fx::FxIndexMap::default(),
139-
alloc_ids: vec![],
140+
alloc_ids: fx::FxIndexMap::default(),
140141
spans: vec![],
141142
types: vec![],
142143
},

compiler/rustc_smir/src/rustc_smir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl<S, R: PartialEq> PartialEq<R> for MaybeStable<S, R> {
196196
pub struct Tables<'tcx> {
197197
pub tcx: TyCtxt<'tcx>,
198198
pub def_ids: FxIndexMap<DefId, stable_mir::DefId>,
199-
pub alloc_ids: Vec<AllocId>,
199+
pub alloc_ids: FxIndexMap<AllocId, stable_mir::AllocId>,
200200
pub spans: Vec<rustc_span::Span>,
201201
pub types: Vec<MaybeStable<stable_mir::ty::TyKind, Ty<'tcx>>>,
202202
}

0 commit comments

Comments
 (0)