Skip to content

Commit 7a89255

Browse files
committed
Avoid some tuple destructuring.
Surprisingly, this is a non-trivial performance win.
1 parent 880318c commit 7a89255

File tree

1 file changed

+7
-5
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+7
-5
lines changed

compiler/rustc_parse/src/parser/mod.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -994,22 +994,24 @@ impl<'a> Parser<'a> {
994994

995995
/// Advance the parser by one token.
996996
pub fn bump(&mut self) {
997-
let (mut next, spacing) = self.token_cursor.inlined_next(self.desugar_doc_comments);
997+
// Note: destructuring here would give nicer code, but it was found in #96210 to be slower
998+
// than `.0`/`.1` access.
999+
let mut next = self.token_cursor.inlined_next(self.desugar_doc_comments);
9981000
self.token_cursor.num_next_calls += 1;
9991001
// We've retrieved an token from the underlying
10001002
// cursor, so we no longer need to worry about
10011003
// an unglued token. See `break_and_eat` for more details
10021004
self.token_cursor.break_last_token = false;
1003-
if next.span.is_dummy() {
1005+
if next.0.span.is_dummy() {
10041006
// Tweak the location for better diagnostics, but keep syntactic context intact.
10051007
let fallback_span = self.token.span;
1006-
next.span = fallback_span.with_ctxt(next.span.ctxt());
1008+
next.0.span = fallback_span.with_ctxt(next.0.span.ctxt());
10071009
}
10081010
debug_assert!(!matches!(
1009-
next.kind,
1011+
next.0.kind,
10101012
token::OpenDelim(token::NoDelim) | token::CloseDelim(token::NoDelim)
10111013
));
1012-
self.inlined_bump_with((next, spacing))
1014+
self.inlined_bump_with(next)
10131015
}
10141016

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

0 commit comments

Comments
 (0)