about summary refs log tree commit diff
path: root/compiler/rustc_resolve
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-08-27 19:23:30 +0000
committerbors <bors@rust-lang.org>2025-08-27 19:23:30 +0000
commitcdb45c87e2cd43495379f7e867e3cc15dcee9f93 (patch)
treef05b1df974331d57c7f8cac1ac6678d7d57464a2 /compiler/rustc_resolve
parentd829133816e337f08fcb1c80c592ff8b16fc73bb (diff)
parentf16d1fcb55d0b9c5d2a6c58e20c4352aa4a7c5fd (diff)
downloadrust-cdb45c87e2cd43495379f7e867e3cc15dcee9f93.tar.gz
rust-cdb45c87e2cd43495379f7e867e3cc15dcee9f93.zip
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`
Diffstat (limited to 'compiler/rustc_resolve')
-rw-r--r--compiler/rustc_resolve/src/rustdoc.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/compiler/rustc_resolve/src/rustdoc.rs b/compiler/rustc_resolve/src/rustdoc.rs
index 6450f63472c..f9f2f84bc50 100644
--- a/compiler/rustc_resolve/src/rustdoc.rs
+++ b/compiler/rustc_resolve/src/rustdoc.rs
@@ -207,8 +207,10 @@ pub fn attrs_to_doc_fragments<'a, A: AttributeExt + Clone + 'a>(
     attrs: impl Iterator<Item = (&'a A, Option<DefId>)>,
     doc_only: bool,
 ) -> (Vec<DocFragment>, ThinVec<A>) {
-    let mut doc_fragments = Vec::new();
-    let mut other_attrs = ThinVec::<A>::new();
+    let (min_size, max_size) = attrs.size_hint();
+    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 {
         if let Some((doc_str, comment_kind)) = attr.doc_str_and_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);
 
     (doc_fragments, other_attrs)