Skip to content

Commit 745ad84

Browse files
committed
Improve parse_dot_or_call_expr_with.
Avoid all the extra work in the very common case where `attrs` is empty.
1 parent 9833b71 commit 745ad84

File tree

1 file changed

+11
-6
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+11
-6
lines changed

Diff for: compiler/rustc_parse/src/parser/expr.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -944,13 +944,18 @@ impl<'a> Parser<'a> {
944944
// Stitch the list of outer attributes onto the return value.
945945
// A little bit ugly, but the best way given the current code
946946
// structure
947-
self.parse_dot_or_call_expr_with_(e0, lo).map(|expr| {
948-
expr.map(|mut expr| {
949-
attrs.extend(expr.attrs);
950-
expr.attrs = attrs;
951-
expr
947+
let res = self.parse_dot_or_call_expr_with_(e0, lo);
948+
if attrs.is_empty() {
949+
res
950+
} else {
951+
res.map(|expr| {
952+
expr.map(|mut expr| {
953+
attrs.extend(expr.attrs);
954+
expr.attrs = attrs;
955+
expr
956+
})
952957
})
953-
})
958+
}
954959
}
955960

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

0 commit comments

Comments
 (0)