about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-07-08 16:53:10 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2024-07-08 16:53:10 +1000
commit99721c84691b3ee7339d307c92a762414527143d (patch)
treea09a6fd6575c630072f8c174c9f4082f4736b46b
parent0ca92de4733bf31262200c6d37e722f534cef4bc (diff)
downloadrust-99721c84691b3ee7339d307c92a762414527143d.tar.gz
rust-99721c84691b3ee7339d307c92a762414527143d.zip
Clear `inner_attr_ranges` regularly.
There's a comment saying we don't do it for performance reasons, but it
doesn't actually affect performance.

The commit also tweaks the control flow, to make clearer that two code
paths are mutually exclusive.
-rw-r--r--compiler/rustc_parse/src/parser/attr_wrapper.rs11
1 files changed, 3 insertions, 8 deletions
diff --git a/compiler/rustc_parse/src/parser/attr_wrapper.rs b/compiler/rustc_parse/src/parser/attr_wrapper.rs
index 38f18022e3c..e9aece13b2e 100644
--- a/compiler/rustc_parse/src/parser/attr_wrapper.rs
+++ b/compiler/rustc_parse/src/parser/attr_wrapper.rs
@@ -352,15 +352,10 @@ impl<'a> Parser<'a> {
             let target = AttrsTarget { attrs: final_attrs.iter().cloned().collect(), tokens };
             self.capture_state.replace_ranges.push((start_pos..end_pos, Some(target)));
             self.capture_state.replace_ranges.extend(inner_attr_replace_ranges);
-        }
-
-        // Only clear our `replace_ranges` when we're finished capturing entirely.
-        if matches!(self.capture_state.capturing, Capturing::No) {
+        } else if matches!(self.capture_state.capturing, Capturing::No) {
+            // Only clear the ranges once we've finished capturing entirely.
             self.capture_state.replace_ranges.clear();
-            // We don't clear `inner_attr_ranges`, as doing so repeatedly
-            // had a measurable performance impact. Most inner attributes that
-            // we insert will get removed - when we drop the parser, we'll free
-            // up the memory used by any attributes that we didn't remove from the map.
+            self.capture_state.inner_attr_ranges.clear();
         }
         Ok(ret)
     }