mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-30 13:06:28 +03:00
Auto merge of #145851 - lolbinarycat:rustdoc-optimize, r=GuillaumeGomez
rustdoc: a few micro-optimizations targeted at build_impl Unsure if these will be anything substantial, but the first one at least should git rid of quite a few branches, second one unsure if it's worth it. r? `@GuillaumeGomez`
This commit is contained in:
@@ -207,8 +207,10 @@ pub fn attrs_to_doc_fragments<'a, A: AttributeExt + Clone + 'a>(
|
|||||||
attrs: impl Iterator<Item = (&'a A, Option<DefId>)>,
|
attrs: impl Iterator<Item = (&'a A, Option<DefId>)>,
|
||||||
doc_only: bool,
|
doc_only: bool,
|
||||||
) -> (Vec<DocFragment>, ThinVec<A>) {
|
) -> (Vec<DocFragment>, ThinVec<A>) {
|
||||||
let mut doc_fragments = Vec::new();
|
let (min_size, max_size) = attrs.size_hint();
|
||||||
let mut other_attrs = ThinVec::<A>::new();
|
let size_hint = max_size.unwrap_or(min_size);
|
||||||
|
let mut doc_fragments = Vec::with_capacity(size_hint);
|
||||||
|
let mut other_attrs = ThinVec::<A>::with_capacity(if doc_only { 0 } else { size_hint });
|
||||||
for (attr, item_id) in attrs {
|
for (attr, item_id) in attrs {
|
||||||
if let Some((doc_str, comment_kind)) = attr.doc_str_and_comment_kind() {
|
if let Some((doc_str, comment_kind)) = attr.doc_str_and_comment_kind() {
|
||||||
let doc = beautify_doc_string(doc_str, comment_kind);
|
let doc = beautify_doc_string(doc_str, comment_kind);
|
||||||
@@ -230,6 +232,9 @@ pub fn attrs_to_doc_fragments<'a, A: AttributeExt + Clone + 'a>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doc_fragments.shrink_to_fit();
|
||||||
|
other_attrs.shrink_to_fit();
|
||||||
|
|
||||||
unindent_doc_fragments(&mut doc_fragments);
|
unindent_doc_fragments(&mut doc_fragments);
|
||||||
|
|
||||||
(doc_fragments, other_attrs)
|
(doc_fragments, other_attrs)
|
||||||
|
|||||||
@@ -572,30 +572,30 @@ pub(crate) fn build_impl(
|
|||||||
super::build_deref_target_impls(cx, &trait_items, ret);
|
super::build_deref_target_impls(cx, &trait_items, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return if the trait itself or any types of the generic parameters are doc(hidden).
|
if !document_hidden {
|
||||||
let mut stack: Vec<&Type> = vec![&for_];
|
// Return if the trait itself or any types of the generic parameters are doc(hidden).
|
||||||
|
let mut stack: Vec<&Type> = vec![&for_];
|
||||||
|
|
||||||
if let Some(did) = trait_.as_ref().map(|t| t.def_id())
|
if let Some(did) = trait_.as_ref().map(|t| t.def_id())
|
||||||
&& !document_hidden
|
|
||||||
&& tcx.is_doc_hidden(did)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(generics) = trait_.as_ref().and_then(|t| t.generics()) {
|
|
||||||
stack.extend(generics);
|
|
||||||
}
|
|
||||||
|
|
||||||
while let Some(ty) = stack.pop() {
|
|
||||||
if let Some(did) = ty.def_id(&cx.cache)
|
|
||||||
&& !document_hidden
|
|
||||||
&& tcx.is_doc_hidden(did)
|
&& tcx.is_doc_hidden(did)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Some(generics) = ty.generics() {
|
|
||||||
|
if let Some(generics) = trait_.as_ref().and_then(|t| t.generics()) {
|
||||||
stack.extend(generics);
|
stack.extend(generics);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while let Some(ty) = stack.pop() {
|
||||||
|
if let Some(did) = ty.def_id(&cx.cache)
|
||||||
|
&& tcx.is_doc_hidden(did)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if let Some(generics) = ty.generics() {
|
||||||
|
stack.extend(generics);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(did) = trait_.as_ref().map(|t| t.def_id()) {
|
if let Some(did) = trait_.as_ref().map(|t| t.def_id()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user