Skip to content

Commit b8e0d0a

Browse files
committed
Auto merge of #60700 - petrochenkov:preintern, r=nnethercote
syntax_pos: Optimize symbol interner pre-filling slightly r? @nnethercote
2 parents 7519eac + aeee1fb commit b8e0d0a

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/libsyntax_pos/symbol.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -463,15 +463,16 @@ pub struct Interner {
463463
impl Interner {
464464
fn prefill(init: &[&str]) -> Self {
465465
let mut this = Interner::default();
466-
for &string in init {
467-
if string == "" {
468-
// We can't allocate empty strings in the arena, so handle this here.
469-
let name = Symbol::new(this.strings.len() as u32);
470-
this.names.insert("", name);
471-
this.strings.push("");
472-
} else {
473-
this.intern(string);
474-
}
466+
this.names.reserve(init.len());
467+
this.strings.reserve(init.len());
468+
469+
// We can't allocate empty strings in the arena, so handle this here.
470+
assert!(keywords::Invalid.name().as_u32() == 0 && init[0].is_empty());
471+
this.names.insert("", keywords::Invalid.name());
472+
this.strings.push("");
473+
474+
for string in &init[1..] {
475+
this.intern(string);
475476
}
476477
this
477478
}

0 commit comments

Comments
 (0)