Skip to content

Commit 99721c8

Browse files
committed
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.
1 parent 0ca92de commit 99721c8

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

compiler/rustc_parse/src/parser/attr_wrapper.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,10 @@ impl<'a> Parser<'a> {
352352
let target = AttrsTarget { attrs: final_attrs.iter().cloned().collect(), tokens };
353353
self.capture_state.replace_ranges.push((start_pos..end_pos, Some(target)));
354354
self.capture_state.replace_ranges.extend(inner_attr_replace_ranges);
355-
}
356-
357-
// Only clear our `replace_ranges` when we're finished capturing entirely.
358-
if matches!(self.capture_state.capturing, Capturing::No) {
355+
} else if matches!(self.capture_state.capturing, Capturing::No) {
356+
// Only clear the ranges once we've finished capturing entirely.
359357
self.capture_state.replace_ranges.clear();
360-
// We don't clear `inner_attr_ranges`, as doing so repeatedly
361-
// had a measurable performance impact. Most inner attributes that
362-
// we insert will get removed - when we drop the parser, we'll free
363-
// up the memory used by any attributes that we didn't remove from the map.
358+
self.capture_state.inner_attr_ranges.clear();
364359
}
365360
Ok(ret)
366361
}

0 commit comments

Comments
 (0)