Skip to content

Commit

Permalink
Improve parse_dot_or_call_expr_with.
Browse files Browse the repository at this point in the history
Avoid all the extra work in the very common case where `attrs` is empty.
  • Loading branch information
nnethercote committed Aug 29, 2022
1 parent b38106b commit c768617
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,13 +944,18 @@ impl<'a> Parser<'a> {
// Stitch the list of outer attributes onto the return value.
// A little bit ugly, but the best way given the current code
// structure
self.parse_dot_or_call_expr_with_(e0, lo).map(|expr| {
expr.map(|mut expr| {
attrs.extend(expr.attrs);
expr.attrs = attrs;
expr
let res = self.parse_dot_or_call_expr_with_(e0, lo);
if attrs.is_empty() {
res
} else {
res.map(|expr| {
expr.map(|mut expr| {
attrs.extend(expr.attrs);
expr.attrs = attrs;
expr
})
})
})
}
}

fn parse_dot_or_call_expr_with_(&mut self, mut e: P<Expr>, lo: Span) -> PResult<'a, P<Expr>> {
Expand Down

0 comments on commit c768617

Please sign in to comment.