Skip to content

Commit 4e700a0

Browse files
committed
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.
1 parent 1bfe40d commit 4e700a0

File tree

1 file changed

+9
-2
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+9
-2
lines changed

compiler/rustc_parse/src/parser/mod.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ impl<'a> Parser<'a> {
463463
parser
464464
}
465465

466+
#[inline]
466467
fn next_tok(&mut self, fallback_span: Span) -> (Token, Spacing) {
467468
loop {
468469
let (mut next, spacing) = if self.desugar_doc_comments {
@@ -998,7 +999,13 @@ impl<'a> Parser<'a> {
998999
}
9991000

10001001
/// Advance the parser by one token using provided token as the next one.
1001-
fn bump_with(&mut self, (next_token, next_spacing): (Token, Spacing)) {
1002+
fn bump_with(&mut self, next: (Token, Spacing)) {
1003+
self.inlined_bump_with(next)
1004+
}
1005+
1006+
/// This always-inlined version should only be used on hot code paths.
1007+
#[inline(always)]
1008+
fn inlined_bump_with(&mut self, (next_token, next_spacing): (Token, Spacing)) {
10021009
// Bumping after EOF is a bad sign, usually an infinite loop.
10031010
if self.prev_token.kind == TokenKind::Eof {
10041011
let msg = "attempted to bump the parser past EOF (may be stuck in a loop)";
@@ -1016,7 +1023,7 @@ impl<'a> Parser<'a> {
10161023
/// Advance the parser by one token.
10171024
pub fn bump(&mut self) {
10181025
let next_token = self.next_tok(self.token.span);
1019-
self.bump_with(next_token);
1026+
self.inlined_bump_with(next_token);
10201027
}
10211028

10221029
/// Look-ahead `dist` tokens of `self.token` and get access to that token there.

0 commit comments

Comments
 (0)