Do not allocate attributes entry if there are no attributes

This saves 8mb.
This commit is contained in:
Chayim Refael Friedman 2024-10-19 23:07:02 +03:00
parent a16a3d345f
commit 61d14ba937
2 changed files with 13 additions and 6 deletions

View File

@ -198,12 +198,14 @@ impl<'a> Ctx<'a> {
}
fn add_attrs(&mut self, item: AttrOwner, attrs: RawAttrs) {
match self.tree.attrs.entry(item) {
Entry::Occupied(mut entry) => {
*entry.get_mut() = entry.get().merge(attrs);
}
Entry::Vacant(entry) => {
entry.insert(attrs);
if !attrs.is_empty() {
match self.tree.attrs.entry(item) {
Entry::Occupied(mut entry) => {
*entry.get_mut() = entry.get().merge(attrs);
}
Entry::Vacant(entry) => {
entry.insert(attrs);
}
}
}
}

View File

@ -26,6 +26,7 @@ use crate::{
/// Syntactical attributes, without filtering of `cfg_attr`s.
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct RawAttrs {
// FIXME: This can become `Box<[Attr]>` if https://internals.rust-lang.org/t/layout-of-dst-box/21728?u=chrefr is accepted.
entries: Option<ThinArc<(), Attr>>,
}
@ -169,6 +170,10 @@ impl RawAttrs {
};
RawAttrs { entries }
}
pub fn is_empty(&self) -> bool {
self.entries.is_none()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]