Skip to content

Commit ec9590e

Browse files
committed
Auto merge of #61612 - nnethercote:improve-parse_bottom_expr, r=<try>
Special-case literals in `parse_bottom_expr`. This makes parsing faster, particularly for code with large constants, for two reasons: - it skips all the keyword comparisons for literals; - it skips the allocation done by the `mk_expr` call in `parse_literal_maybe_minus`. r? @petrochenkov
2 parents c5295ac + a4952ba commit ec9590e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/libsyntax/parse/parser.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,21 @@ impl<'a> Parser<'a> {
19941994

19951995
// Note: when adding new syntax here, don't forget to adjust Token::can_begin_expr().
19961996
match self.token {
1997+
// This match arm is a special-case of the `_` match arm below and
1998+
// could be removed without changing functionality, but it's faster
1999+
// to have it here, especially for programs with large constants.
2000+
token::Literal(_) => {
2001+
match self.parse_lit() {
2002+
Ok(literal) => {
2003+
hi = self.prev_span;
2004+
ex = ExprKind::Lit(literal);
2005+
}
2006+
Err(mut err) => {
2007+
self.cancel(&mut err);
2008+
return Err(self.expected_expression_found());
2009+
}
2010+
}
2011+
}
19972012
token::OpenDelim(token::Paren) => {
19982013
self.bump();
19992014

0 commit comments

Comments
 (0)