diff options
| author | bors <bors@rust-lang.org> | 2019-06-12 16:30:05 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-06-12 16:30:05 +0000 |
| commit | 55cee44671ecb0869cc7fbac0ad62f6236893d06 (patch) | |
| tree | f8a3b98b4307ad8b6941b1120277ec10e796e625 /src/libsyntax/parse | |
| parent | 24ddd1615419be89828fb5628e3c14af86c08b01 (diff) | |
| parent | 35b5f4377028e34dc4df1ce67c225d2926c6c7a7 (diff) | |
| download | rust-55cee44671ecb0869cc7fbac0ad62f6236893d06.tar.gz rust-55cee44671ecb0869cc7fbac0ad62f6236893d06.zip | |
Auto merge of #61612 - nnethercote:improve-parse_bottom_expr, r=petrochenkov
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
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b6388f08e73..78eeb512206 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1994,8 +1994,29 @@ impl<'a> Parser<'a> { let ex: ExprKind; + macro_rules! parse_lit { + () => { + match self.parse_lit() { + Ok(literal) => { + hi = self.prev_span; + ex = ExprKind::Lit(literal); + } + Err(mut err) => { + self.cancel(&mut err); + return Err(self.expected_expression_found()); + } + } + } + } + // Note: when adding new syntax here, don't forget to adjust TokenKind::can_begin_expr(). match self.token.kind { + // This match arm is a special-case of the `_` match arm below and + // could be removed without changing functionality, but it's faster + // to have it here, especially for programs with large constants. + token::Literal(_) => { + parse_lit!() + } token::OpenDelim(token::Paren) => { self.bump(); @@ -2241,16 +2262,7 @@ impl<'a> Parser<'a> { self.bump(); return Ok(self.mk_expr(self.token.span, ExprKind::Err, ThinVec::new())); } - match self.parse_literal_maybe_minus() { - Ok(expr) => { - hi = expr.span; - ex = expr.node.clone(); - } - Err(mut err) => { - self.cancel(&mut err); - return Err(self.expected_expression_found()); - } - } + parse_lit!() } } } |
