Skip to content

Commit bbc6774

Browse files
committed
Auto merge of #76782 - lzutao:rd-cap, r=jyn514
Specialize merge_attrs in good case Just a non-important micro-optimization. r? `@jyn514`
2 parents 2cbc570 + 2818032 commit bbc6774

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/librustdoc/clean/inline.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,17 @@ fn merge_attrs(
306306
attrs: Attrs<'_>,
307307
other_attrs: Option<Attrs<'_>>,
308308
) -> clean::Attributes {
309-
let mut merged_attrs: Vec<ast::Attribute> = Vec::with_capacity(attrs.len());
310-
// If we have additional attributes (from a re-export),
309+
// NOTE: If we have additional attributes (from a re-export),
311310
// always insert them first. This ensure that re-export
312311
// doc comments show up before the original doc comments
313312
// when we render them.
314-
if let Some(a) = other_attrs {
315-
merged_attrs.extend(a.iter().cloned());
316-
}
317-
merged_attrs.extend(attrs.to_vec());
313+
let merged_attrs = if let Some(inner) = other_attrs {
314+
let mut both = inner.to_vec();
315+
both.extend_from_slice(attrs);
316+
both
317+
} else {
318+
attrs.to_vec()
319+
};
318320
merged_attrs.clean(cx)
319321
}
320322

0 commit comments

Comments
 (0)