diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-03-07 15:17:38 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-03-22 11:01:53 +1100 |
| commit | 4e700a023c2706136012c39cc30d8bf431d83f0a (patch) | |
| tree | 829d658a060f1c42459742e08f02b9c1a04f22de /compiler/rustc_parse/src | |
| parent | 1bfe40d11c3630254504fb73eeccfca28d50df52 (diff) | |
| download | rust-4e700a023c2706136012c39cc30d8bf431d83f0a.tar.gz rust-4e700a023c2706136012c39cc30d8bf431d83f0a.zip | |
Split `Parser::bump_with` into inlined and non-inlined halves.
The call site within `Parser::bump` is hot. Also add an inline annotation to `Parser::next_tok`. It was already being inlined by the compiler; this just makes sure that continues.
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 4e229918b63..5c773410891 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -463,6 +463,7 @@ impl<'a> Parser<'a> { parser } + #[inline] fn next_tok(&mut self, fallback_span: Span) -> (Token, Spacing) { loop { let (mut next, spacing) = if self.desugar_doc_comments { @@ -998,7 +999,13 @@ impl<'a> Parser<'a> { } /// Advance the parser by one token using provided token as the next one. - fn bump_with(&mut self, (next_token, next_spacing): (Token, Spacing)) { + fn bump_with(&mut self, next: (Token, Spacing)) { + self.inlined_bump_with(next) + } + + /// This always-inlined version should only be used on hot code paths. + #[inline(always)] + fn inlined_bump_with(&mut self, (next_token, next_spacing): (Token, Spacing)) { // Bumping after EOF is a bad sign, usually an infinite loop. if self.prev_token.kind == TokenKind::Eof { let msg = "attempted to bump the parser past EOF (may be stuck in a loop)"; @@ -1016,7 +1023,7 @@ impl<'a> Parser<'a> { /// Advance the parser by one token. pub fn bump(&mut self) { let next_token = self.next_tok(self.token.span); - self.bump_with(next_token); + self.inlined_bump_with(next_token); } /// Look-ahead `dist` tokens of `self.token` and get access to that token there. |
