Skip to content

rustdoc: Speed up TypeAliasPart::get #141421

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

Merged
merged 3 commits into from
May 24, 2025
Merged
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
71 changes: 36 additions & 35 deletions src/librustdoc/html/render/write_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ impl TypeAliasPart {
.impl_
.values()
.flat_map(|AliasedTypeImpl { impl_, type_aliases }| {
let mut ret = Vec::new();
let mut ret: Vec<AliasSerializableImpl> = Vec::new();
let trait_ = impl_
.inner_impl()
.trait_
Expand All @@ -623,42 +623,43 @@ impl TypeAliasPart {
for &(type_alias_fqp, type_alias_item) in type_aliases {
cx.id_map.borrow_mut().clear();
cx.deref_id_map.borrow_mut().clear();
let target_did = impl_
.inner_impl()
.trait_
.as_ref()
.map(|trait_| trait_.def_id())
.or_else(|| impl_.inner_impl().for_.def_id(&cx.shared.cache));
let provided_methods;
let assoc_link = if let Some(target_did) = target_did {
provided_methods = impl_.inner_impl().provided_trait_methods(cx.tcx());
AssocItemLink::GotoSource(ItemId::DefId(target_did), &provided_methods)
} else {
AssocItemLink::Anchor(None)
};
let text = super::render_impl(
cx,
impl_,
type_alias_item,
assoc_link,
RenderMode::Normal,
None,
&[],
ImplRenderingParameters {
show_def_docs: true,
show_default_items: true,
show_non_assoc_items: true,
toggle_open_by_default: true,
},
)
.to_string();
let type_alias_fqp = (*type_alias_fqp).iter().join("::");
if Some(&text) == ret.last().map(|s: &AliasSerializableImpl| &s.text) {
ret.last_mut()
.expect("already established that ret.last() is Some()")
.aliases
.push(type_alias_fqp);
if let Some(last) = ret.last_mut() {
last.aliases.push(type_alias_fqp);
} else {
let target_did = impl_
.inner_impl()
.trait_
.as_ref()
.map(|trait_| trait_.def_id())
.or_else(|| impl_.inner_impl().for_.def_id(&cx.shared.cache));
let provided_methods;
let assoc_link = if let Some(target_did) = target_did {
provided_methods =
impl_.inner_impl().provided_trait_methods(cx.tcx());
AssocItemLink::GotoSource(
ItemId::DefId(target_did),
&provided_methods,
)
} else {
AssocItemLink::Anchor(None)
};
let text = super::render_impl(
cx,
impl_,
type_alias_item,
assoc_link,
RenderMode::Normal,
None,
&[],
ImplRenderingParameters {
show_def_docs: true,
show_default_items: true,
show_non_assoc_items: true,
toggle_open_by_default: true,
},
)
.to_string();
ret.push(AliasSerializableImpl {
text,
trait_: trait_.clone(),
Expand Down
Loading