@@ -207,8 +207,10 @@ pub fn attrs_to_doc_fragments<'a, A: AttributeExt + Clone + 'a>(
207
207
attrs : impl Iterator < Item = ( & ' a A , Option < DefId > ) > ,
208
208
doc_only : bool ,
209
209
) -> ( 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 } ) ;
212
214
for ( attr, item_id) in attrs {
213
215
if let Some ( ( doc_str, comment_kind) ) = attr. doc_str_and_comment_kind ( ) {
214
216
let doc = beautify_doc_string ( doc_str, comment_kind) ;
@@ -230,6 +232,9 @@ pub fn attrs_to_doc_fragments<'a, A: AttributeExt + Clone + 'a>(
230
232
}
231
233
}
232
234
235
+ doc_fragments. shrink_to_fit ( ) ;
236
+ other_attrs. shrink_to_fit ( ) ;
237
+
233
238
unindent_doc_fragments ( & mut doc_fragments) ;
234
239
235
240
( doc_fragments, other_attrs)
0 commit comments