Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ab9bbf4

Browse files
committedJun 4, 2019
Avoid unnecessary rust_2018 calls.
The commit combines two calls into one by saving the result in a local variable. The commit also moves the check for `async` later, so that when a different keyword is present the `rust_2018` call will be avoided completely.
1 parent 425736d commit ab9bbf4

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed
 

‎src/libsyntax/parse/parser.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -2083,13 +2083,6 @@ impl<'a> Parser<'a> {
20832083
hi = path.span;
20842084
return Ok(self.mk_expr(lo.to(hi), ExprKind::Path(Some(qself), path), attrs));
20852085
}
2086-
if self.span.rust_2018() && self.check_keyword(kw::Async) {
2087-
return if self.is_async_block() { // check for `async {` and `async move {`
2088-
self.parse_async_block(attrs)
2089-
} else {
2090-
self.parse_lambda_expr(attrs)
2091-
};
2092-
}
20932086
if self.check_keyword(kw::Move) || self.check_keyword(kw::Static) {
20942087
return self.parse_lambda_expr(attrs);
20952088
}
@@ -2161,6 +2154,16 @@ impl<'a> Parser<'a> {
21612154
assert!(self.eat_keyword(kw::Try));
21622155
return self.parse_try_block(lo, attrs);
21632156
}
2157+
2158+
// Span::rust_2018() is somewhat expensive; don't get it repeatedly.
2159+
let is_span_rust_2018 = self.span.rust_2018();
2160+
if is_span_rust_2018 && self.check_keyword(kw::Async) {
2161+
return if self.is_async_block() { // check for `async {` and `async move {`
2162+
self.parse_async_block(attrs)
2163+
} else {
2164+
self.parse_lambda_expr(attrs)
2165+
};
2166+
}
21642167
if self.eat_keyword(kw::Return) {
21652168
if self.token.can_begin_expr() {
21662169
let e = self.parse_expr()?;
@@ -2196,7 +2199,7 @@ impl<'a> Parser<'a> {
21962199
db.span_label(self.span, "expected expression");
21972200
db.note("variable declaration using `let` is a statement");
21982201
return Err(db);
2199-
} else if self.span.rust_2018() && self.eat_keyword(kw::Await) {
2202+
} else if is_span_rust_2018 && self.eat_keyword(kw::Await) {
22002203
let (await_hi, e_kind) = self.parse_await_macro_or_alt(lo, self.prev_span)?;
22012204
hi = await_hi;
22022205
ex = e_kind;

0 commit comments

Comments
 (0)
Please sign in to comment.