diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-08-23 13:28:20 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-08-29 15:42:16 +1000 |
| commit | c768617f6fae82388df9ac1a5907c30fcba3ef44 (patch) | |
| tree | cf047aa50e860a84716cd949b49903c851f158d1 /compiler/rustc_parse/src | |
| parent | b38106b6d8478fbfbded5403ee31c056c71cef48 (diff) | |
| download | rust-c768617f6fae82388df9ac1a5907c30fcba3ef44.tar.gz rust-c768617f6fae82388df9ac1a5907c30fcba3ef44.zip | |
Improve `parse_dot_or_call_expr_with`.
Avoid all the extra work in the very common case where `attrs` is empty.
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 18aa109d7a6..f28897aaeb0 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -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>> { |
