Skip to content

Commit f16d1fc

Browse files
committed
use size_hint in attrs_to_doc_fragments
1 parent 2e969c7 commit f16d1fc

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

compiler/rustc_resolve/src/rustdoc.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,10 @@ pub fn attrs_to_doc_fragments<'a, A: AttributeExt + Clone + 'a>(
207207
attrs: impl Iterator<Item = (&'a A, Option<DefId>)>,
208208
doc_only: bool,
209209
) -> (Vec<DocFragment>, ThinVec<A>) {
210-
let mut doc_fragments = Vec::new();
211-
let mut other_attrs = ThinVec::<A>::new();
210+
let (min_size, max_size) = attrs.size_hint();
211+
let size_hint = max_size.unwrap_or(min_size);
212+
let mut doc_fragments = Vec::with_capacity(size_hint);
213+
let mut other_attrs = ThinVec::<A>::with_capacity(if doc_only { 0 } else { size_hint });
212214
for (attr, item_id) in attrs {
213215
if let Some((doc_str, comment_kind)) = attr.doc_str_and_comment_kind() {
214216
let doc = beautify_doc_string(doc_str, comment_kind);
@@ -230,6 +232,9 @@ pub fn attrs_to_doc_fragments<'a, A: AttributeExt + Clone + 'a>(
230232
}
231233
}
232234

235+
doc_fragments.shrink_to_fit();
236+
other_attrs.shrink_to_fit();
237+
233238
unindent_doc_fragments(&mut doc_fragments);
234239

235240
(doc_fragments, other_attrs)

0 commit comments

Comments
 (0)