Skip to content

Commit 105354d

Browse files
committed
Auto merge of #141421 - nnethercote:TypeAliasPart-get, r=GuillaumeGomez
rustdoc: Speed up `TypeAliasPart::get` Big speedups here on a couple of the benchmarks. r? `@GuillaumeGomez`
2 parents 80c3498 + dfe8fe8 commit 105354d

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

src/librustdoc/html/render/write_shared.rs

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ impl TypeAliasPart {
611611
.impl_
612612
.values()
613613
.flat_map(|AliasedTypeImpl { impl_, type_aliases }| {
614-
let mut ret = Vec::new();
614+
let mut ret: Vec<AliasSerializableImpl> = Vec::new();
615615
let trait_ = impl_
616616
.inner_impl()
617617
.trait_
@@ -623,42 +623,43 @@ impl TypeAliasPart {
623623
for &(type_alias_fqp, type_alias_item) in type_aliases {
624624
cx.id_map.borrow_mut().clear();
625625
cx.deref_id_map.borrow_mut().clear();
626-
let target_did = impl_
627-
.inner_impl()
628-
.trait_
629-
.as_ref()
630-
.map(|trait_| trait_.def_id())
631-
.or_else(|| impl_.inner_impl().for_.def_id(&cx.shared.cache));
632-
let provided_methods;
633-
let assoc_link = if let Some(target_did) = target_did {
634-
provided_methods = impl_.inner_impl().provided_trait_methods(cx.tcx());
635-
AssocItemLink::GotoSource(ItemId::DefId(target_did), &provided_methods)
636-
} else {
637-
AssocItemLink::Anchor(None)
638-
};
639-
let text = super::render_impl(
640-
cx,
641-
impl_,
642-
type_alias_item,
643-
assoc_link,
644-
RenderMode::Normal,
645-
None,
646-
&[],
647-
ImplRenderingParameters {
648-
show_def_docs: true,
649-
show_default_items: true,
650-
show_non_assoc_items: true,
651-
toggle_open_by_default: true,
652-
},
653-
)
654-
.to_string();
655626
let type_alias_fqp = (*type_alias_fqp).iter().join("::");
656-
if Some(&text) == ret.last().map(|s: &AliasSerializableImpl| &s.text) {
657-
ret.last_mut()
658-
.expect("already established that ret.last() is Some()")
659-
.aliases
660-
.push(type_alias_fqp);
627+
if let Some(last) = ret.last_mut() {
628+
last.aliases.push(type_alias_fqp);
661629
} else {
630+
let target_did = impl_
631+
.inner_impl()
632+
.trait_
633+
.as_ref()
634+
.map(|trait_| trait_.def_id())
635+
.or_else(|| impl_.inner_impl().for_.def_id(&cx.shared.cache));
636+
let provided_methods;
637+
let assoc_link = if let Some(target_did) = target_did {
638+
provided_methods =
639+
impl_.inner_impl().provided_trait_methods(cx.tcx());
640+
AssocItemLink::GotoSource(
641+
ItemId::DefId(target_did),
642+
&provided_methods,
643+
)
644+
} else {
645+
AssocItemLink::Anchor(None)
646+
};
647+
let text = super::render_impl(
648+
cx,
649+
impl_,
650+
type_alias_item,
651+
assoc_link,
652+
RenderMode::Normal,
653+
None,
654+
&[],
655+
ImplRenderingParameters {
656+
show_def_docs: true,
657+
show_default_items: true,
658+
show_non_assoc_items: true,
659+
toggle_open_by_default: true,
660+
},
661+
)
662+
.to_string();
662663
ret.push(AliasSerializableImpl {
663664
text,
664665
trait_: trait_.clone(),

0 commit comments

Comments
 (0)