Skip to content

Commit 1f828f0

Browse files
Improve performance of first_non_private
1 parent 988729d commit 1f828f0

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

src/librustdoc/clean/mod.rs

+18-22
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ fn first_non_private<'tcx>(
15451545
if let Some((segments, span)) = saved_path {
15461546
return Some(first_non_private_clean_path(cx, path, segments, span));
15471547
}
1548-
let (parent_def_id, mut ident) = match &path.segments[..] {
1548+
let (parent_def_id, ident) = match &path.segments[..] {
15491549
[] => return None,
15501550
// Relative paths are available in the same scope as the owner.
15511551
[leaf] => (cx.tcx.local_parent(hir_id.owner.def_id), leaf.ident),
@@ -1569,6 +1569,7 @@ fn first_non_private<'tcx>(
15691569
// Absolute paths are not. We start from the parent of the item.
15701570
[.., parent, leaf] => (parent.res.opt_def_id()?.as_local()?, leaf.ident),
15711571
};
1572+
let hir = cx.tcx.hir();
15721573
// First we try to get the `DefId` of the item.
15731574
for child in
15741575
cx.tcx.module_children_local(parent_def_id).iter().filter(move |c| c.ident == ident)
@@ -1581,29 +1582,24 @@ fn first_non_private<'tcx>(
15811582
let mut last_path_res = None;
15821583
'reexps: for reexp in child.reexport_chain.iter() {
15831584
if let Some(use_def_id) = reexp.id() &&
1584-
let Some(local_use_def_id) = use_def_id.as_local()
1585+
let Some(local_use_def_id) = use_def_id.as_local() &&
1586+
let Some(hir::Node::Item(item)) = hir.find_by_def_id(local_use_def_id) &&
1587+
let hir::ItemKind::Use(path, _) = item.kind
15851588
{
1586-
let hir = cx.tcx.hir();
1587-
for item_id in hir.module_items(cx.tcx.local_parent(local_use_def_id)) {
1588-
let item = hir.item(item_id);
1589-
if item.ident == ident && let hir::ItemKind::Use(path, _) = item.kind {
1590-
for res in &path.res {
1591-
if let Res::Def(DefKind::Ctor(..), _) | Res::SelfCtor(..) = res {
1592-
continue;
1593-
}
1594-
if (cx.render_options.document_hidden ||
1595-
!cx.tcx.is_doc_hidden(use_def_id)) &&
1596-
// We never check for "cx.render_options.document_private"
1597-
// because if a re-export is not fully public, it's never
1598-
// documented.
1599-
cx.tcx.local_visibility(local_use_def_id).is_public() {
1600-
break 'reexps;
1601-
}
1602-
ident = path.segments.last().unwrap().ident;
1603-
last_path_res = Some((path, res));
1604-
continue 'reexps;
1605-
}
1589+
for res in &path.res {
1590+
if let Res::Def(DefKind::Ctor(..), _) | Res::SelfCtor(..) = res {
1591+
continue;
1592+
}
1593+
if (cx.render_options.document_hidden ||
1594+
!cx.tcx.is_doc_hidden(use_def_id)) &&
1595+
// We never check for "cx.render_options.document_private"
1596+
// because if a re-export is not fully public, it's never
1597+
// documented.
1598+
cx.tcx.local_visibility(local_use_def_id).is_public() {
1599+
break 'reexps;
16061600
}
1601+
last_path_res = Some((path, res));
1602+
continue 'reexps;
16071603
}
16081604
}
16091605
}

0 commit comments

Comments
 (0)