Skip to content

Commit 7d1547d

Browse files
committed
rustc_span: use IndexSet in SpanInterner
1 parent 4efc7e9 commit 7d1547d

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/librustc_span/span_encoding.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::hygiene::SyntaxContext;
88
use crate::SESSION_GLOBALS;
99
use crate::{BytePos, SpanData};
1010

11-
use rustc_data_structures::fx::FxHashMap;
11+
use rustc_data_structures::fx::FxIndexSet;
1212

1313
/// A compressed span.
1414
///
@@ -111,25 +111,18 @@ impl Span {
111111

112112
#[derive(Default)]
113113
pub struct SpanInterner {
114-
spans: FxHashMap<SpanData, u32>,
115-
span_data: Vec<SpanData>,
114+
spans: FxIndexSet<SpanData>,
116115
}
117116

118117
impl SpanInterner {
119118
fn intern(&mut self, span_data: &SpanData) -> u32 {
120-
if let Some(index) = self.spans.get(span_data) {
121-
return *index;
122-
}
123-
124-
let index = self.spans.len() as u32;
125-
self.span_data.push(*span_data);
126-
self.spans.insert(*span_data, index);
127-
index
119+
let (index, _) = self.spans.insert_full(*span_data);
120+
index as u32
128121
}
129122

130123
#[inline]
131124
fn get(&self, index: u32) -> &SpanData {
132-
&self.span_data[index as usize]
125+
&self.spans[index as usize]
133126
}
134127
}
135128

0 commit comments

Comments
 (0)