Skip to content

Commit bccf006

Browse files
Do not allocate attributes entry if there are no attributes
This saves 8mb.
1 parent d0933cc commit bccf006

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

crates/hir-def/src/item_tree/lower.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,14 @@ impl<'a> Ctx<'a> {
198198
}
199199

200200
fn add_attrs(&mut self, item: AttrOwner, attrs: RawAttrs) {
201-
match self.tree.attrs.entry(item) {
202-
Entry::Occupied(mut entry) => {
203-
*entry.get_mut() = entry.get().merge(attrs);
204-
}
205-
Entry::Vacant(entry) => {
206-
entry.insert(attrs);
201+
if !attrs.is_empty() {
202+
match self.tree.attrs.entry(item) {
203+
Entry::Occupied(mut entry) => {
204+
*entry.get_mut() = entry.get().merge(attrs);
205+
}
206+
Entry::Vacant(entry) => {
207+
entry.insert(attrs);
208+
}
207209
}
208210
}
209211
}

crates/hir-expand/src/attrs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate::{
2626
/// Syntactical attributes, without filtering of `cfg_attr`s.
2727
#[derive(Default, Debug, Clone, PartialEq, Eq)]
2828
pub struct RawAttrs {
29+
// FIXME: This can become `Box<[Attr]>` if https://internals.rust-lang.org/t/layout-of-dst-box/21728?u=chrefr is accepted.
2930
entries: Option<ThinArc<(), Attr>>,
3031
}
3132

@@ -169,6 +170,10 @@ impl RawAttrs {
169170
};
170171
RawAttrs { entries }
171172
}
173+
174+
pub fn is_empty(&self) -> bool {
175+
self.entries.is_none()
176+
}
172177
}
173178

174179
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

0 commit comments

Comments
 (0)