Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent to compute Item attributes twice #82265

Merged
merged 2 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,10 @@ crate fn build_impl(

debug!("build_impl: impl {:?} for {:?}", trait_.def_id(), for_.def_id());

let mut item = clean::Item::from_def_id_and_parts(
let attrs = box merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs);
debug!("merged_attrs={:?}", attrs);

ret.push(clean::Item::from_def_id_and_attrs_and_parts(
did,
None,
clean::ImplItem(clean::Impl {
Expand All @@ -430,11 +433,9 @@ crate fn build_impl(
synthetic: false,
blanket_impl: None,
}),
attrs,
cx,
);
item.attrs = box merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs);
debug!("merged_attrs={:?}", item.attrs);
ret.push(item);
));
}

fn build_module(
Expand Down
18 changes: 17 additions & 1 deletion src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ impl Item {
name: Option<Symbol>,
kind: ItemKind,
cx: &mut DocContext<'_>,
) -> Item {
Self::from_def_id_and_attrs_and_parts(
def_id,
name,
kind,
box cx.tcx.get_attrs(def_id).clean(cx),
Copy link
Contributor

@bugadani bugadani Feb 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How common is the case where attrs are empty? That box I think can be optimized (by turning the field into Option<Box<>>). I was planning on doing that, but unless it's a bigger change, it could probably be part of this PR.

Not entirely sure, though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't bet on that to be honest. Trying to be too clever never ends well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll see, I guess I'll submit a PR anyway. But true, the additional complexity might backfire a bit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I'd call that too clever. @bugadani I'd be interested in seeing that PR :)

cx,
)
}

pub fn from_def_id_and_attrs_and_parts(
def_id: DefId,
name: Option<Symbol>,
kind: ItemKind,
attrs: Box<Attributes>,
cx: &mut DocContext<'_>,
) -> Item {
debug!("name={:?}, def_id={:?}", name, def_id);

Expand All @@ -157,7 +173,7 @@ impl Item {
kind: box kind,
name,
source: source.clean(cx),
attrs: box cx.tcx.get_attrs(def_id).clean(cx),
attrs,
visibility: cx.tcx.visibility(def_id).clean(cx),
}
}
Expand Down