mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Do not allocate attributes entry if there are no attributes
This saves 8mb.
This commit is contained in:
parent
d0933cc097
commit
bccf0062b7
2 changed files with 13 additions and 6 deletions
|
@ -198,6 +198,7 @@ impl<'a> Ctx<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_attrs(&mut self, item: AttrOwner, attrs: RawAttrs) {
|
fn add_attrs(&mut self, item: AttrOwner, attrs: RawAttrs) {
|
||||||
|
if !attrs.is_empty() {
|
||||||
match self.tree.attrs.entry(item) {
|
match self.tree.attrs.entry(item) {
|
||||||
Entry::Occupied(mut entry) => {
|
Entry::Occupied(mut entry) => {
|
||||||
*entry.get_mut() = entry.get().merge(attrs);
|
*entry.get_mut() = entry.get().merge(attrs);
|
||||||
|
@ -207,6 +208,7 @@ impl<'a> Ctx<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn lower_assoc_item(&mut self, item_node: &ast::AssocItem) -> Option<AssocItem> {
|
fn lower_assoc_item(&mut self, item_node: &ast::AssocItem) -> Option<AssocItem> {
|
||||||
let item: AssocItem = match item_node {
|
let item: AssocItem = match item_node {
|
||||||
|
|
|
@ -26,6 +26,7 @@ use crate::{
|
||||||
/// Syntactical attributes, without filtering of `cfg_attr`s.
|
/// Syntactical attributes, without filtering of `cfg_attr`s.
|
||||||
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct RawAttrs {
|
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>>,
|
entries: Option<ThinArc<(), Attr>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +170,10 @@ impl RawAttrs {
|
||||||
};
|
};
|
||||||
RawAttrs { entries }
|
RawAttrs { entries }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.entries.is_none()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue