Don't arena-allocate static symbols.

It's just a waste of memory. This also gets rid of the special case for
"".
This commit is contained in:
Nicholas Nethercote 2019-05-23 17:47:53 +10:00
parent 27cc0db7a2
commit e396f99255

View File

@ -866,20 +866,13 @@ pub struct Interner {
} }
impl Interner { impl Interner {
fn prefill(init: &[&str]) -> Self { fn prefill(init: &[&'static str]) -> Self {
let mut this = Interner::default(); let symbols = (0 .. init.len() as u32).map(Symbol::new);
this.names.reserve(init.len()); Interner {
this.strings.reserve(init.len()); strings: init.to_vec(),
names: init.iter().copied().zip(symbols).collect(),
// We can't allocate empty strings in the arena, so handle this here. ..Default::default()
assert!(kw::Invalid.as_u32() == 0 && init[0].is_empty());
this.names.insert("", kw::Invalid);
this.strings.push("");
for string in &init[1..] {
this.intern(string);
} }
this
} }
pub fn intern(&mut self, string: &str) -> Symbol { pub fn intern(&mut self, string: &str) -> Symbol {