]> git.lizzy.rs Git - rust.git/commitdiff
Don't arena-allocate static symbols.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 23 May 2019 07:47:53 +0000 (17:47 +1000)
committerNicholas Nethercote <nnethercote@mozilla.com>
Fri, 24 May 2019 10:11:52 +0000 (20:11 +1000)
It's just a waste of memory. This also gets rid of the special case for
"".

src/libsyntax_pos/symbol.rs

index b1e1a056db4adaa736f8cd057adc33bc520c8835..26422e891c53643846c5a095479022c6113982d5 100644 (file)
@@ -866,20 +866,13 @@ pub struct Interner {
 }
 
 impl Interner {
-    fn prefill(init: &[&str]) -> Self {
-        let mut this = Interner::default();
-        this.names.reserve(init.len());
-        this.strings.reserve(init.len());
-
-        // We can't allocate empty strings in the arena, so handle this here.
-        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);
+    fn prefill(init: &[&'static str]) -> Self {
+        let symbols = (0 .. init.len() as u32).map(Symbol::new);
+        Interner {
+            strings: init.to_vec(),
+            names: init.iter().copied().zip(symbols).collect(),
+            ..Default::default()
         }
-        this
     }
 
     pub fn intern(&mut self, string: &str) -> Symbol {