diff options
| author | bors <bors@rust-lang.org> | 2019-05-11 06:42:36 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-05-11 06:42:36 +0000 |
| commit | b8e0d0a2aa4f18d76a701150fccb67533f377368 (patch) | |
| tree | 589f98340720aedeec89f0171205bf8ce36aeb00 /src | |
| parent | 7519eaca9a2565cd60e645b2dfda61f205bd25df (diff) | |
| parent | aeee1fb1f250accccd85f8d7f7a501ed81db68e8 (diff) | |
| download | rust-b8e0d0a2aa4f18d76a701150fccb67533f377368.tar.gz rust-b8e0d0a2aa4f18d76a701150fccb67533f377368.zip | |
Auto merge of #60700 - petrochenkov:preintern, r=nnethercote
syntax_pos: Optimize symbol interner pre-filling slightly r? @nnethercote
Diffstat (limited to 'src')
| -rw-r--r-- | src/libsyntax_pos/symbol.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index d0ba09af30b..c0c9c2a1000 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -463,15 +463,16 @@ pub struct Interner { impl Interner { fn prefill(init: &[&str]) -> Self { let mut this = Interner::default(); - for &string in init { - if string == "" { - // We can't allocate empty strings in the arena, so handle this here. - let name = Symbol::new(this.strings.len() as u32); - this.names.insert("", name); - this.strings.push(""); - } else { - this.intern(string); - } + this.names.reserve(init.len()); + this.strings.reserve(init.len()); + + // We can't allocate empty strings in the arena, so handle this here. + assert!(keywords::Invalid.name().as_u32() == 0 && init[0].is_empty()); + this.names.insert("", keywords::Invalid.name()); + this.strings.push(""); + + for string in &init[1..] { + this.intern(string); } this } |
