File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
compiler/rustc_resolve/src Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff 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)
You can’t perform that action at this time.
0 commit comments