Skip to content

Commit bc235ee

Browse files
authored
Rollup merge of rust-lang#61077 - nnethercote:tweak-prefill, r=petrochenkov
Don't arena-allocate static symbols. It's just a waste of memory. This also gets rid of the special case for "". r? @petrochenkov
2 parents 04f81f2 + e396f99 commit bc235ee

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/libsyntax_pos/symbol.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -909,20 +909,13 @@ pub struct Interner {
909909
}
910910

911911
impl Interner {
912-
fn prefill(init: &[&str]) -> Self {
913-
let mut this = Interner::default();
914-
this.names.reserve(init.len());
915-
this.strings.reserve(init.len());
916-
917-
// We can't allocate empty strings in the arena, so handle this here.
918-
assert!(kw::Invalid.as_u32() == 0 && init[0].is_empty());
919-
this.names.insert("", kw::Invalid);
920-
this.strings.push("");
921-
922-
for string in &init[1..] {
923-
this.intern(string);
912+
fn prefill(init: &[&'static str]) -> Self {
913+
let symbols = (0 .. init.len() as u32).map(Symbol::new);
914+
Interner {
915+
strings: init.to_vec(),
916+
names: init.iter().copied().zip(symbols).collect(),
917+
..Default::default()
924918
}
925-
this
926919
}
927920

928921
pub fn intern(&mut self, string: &str) -> Symbol {

0 commit comments

Comments
 (0)