Skip to content

Commit aeee1fb

Browse files
committed
syntax_pos: Optimize symbol interner pre-filling slightly
1 parent 0ac53da commit aeee1fb

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/libsyntax_pos/symbol.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -453,15 +453,16 @@ pub struct Interner {
453453
impl Interner {
454454
fn prefill(init: &[&str]) -> Self {
455455
let mut this = Interner::default();
456-
for &string in init {
457-
if string == "" {
458-
// We can't allocate empty strings in the arena, so handle this here.
459-
let name = Symbol::new(this.strings.len() as u32);
460-
this.names.insert("", name);
461-
this.strings.push("");
462-
} else {
463-
this.intern(string);
464-
}
456+
this.names.reserve(init.len());
457+
this.strings.reserve(init.len());
458+
459+
// We can't allocate empty strings in the arena, so handle this here.
460+
assert!(keywords::Invalid.name().as_u32() == 0 && init[0].is_empty());
461+
this.names.insert("", keywords::Invalid.name());
462+
this.strings.push("");
463+
464+
for string in &init[1..] {
465+
this.intern(string);
465466
}
466467
this
467468
}

0 commit comments

Comments
 (0)