1
Fork 0

Auto merge of #76782 - lzutao:rd-cap, r=jyn514

Specialize merge_attrs in good case

Just a non-important micro-optimization.
r? `@jyn514`
This commit is contained in:
bors 2020-09-18 21:31:08 +00:00
commit bbc677480d

View file

@ -306,15 +306,17 @@ fn merge_attrs(
attrs: Attrs<'_>, attrs: Attrs<'_>,
other_attrs: Option<Attrs<'_>>, other_attrs: Option<Attrs<'_>>,
) -> clean::Attributes { ) -> clean::Attributes {
let mut merged_attrs: Vec<ast::Attribute> = Vec::with_capacity(attrs.len()); // NOTE: If we have additional attributes (from a re-export),
// If we have additional attributes (from a re-export),
// always insert them first. This ensure that re-export // always insert them first. This ensure that re-export
// doc comments show up before the original doc comments // doc comments show up before the original doc comments
// when we render them. // when we render them.
if let Some(a) = other_attrs { let merged_attrs = if let Some(inner) = other_attrs {
merged_attrs.extend(a.iter().cloned()); let mut both = inner.to_vec();
} both.extend_from_slice(attrs);
merged_attrs.extend(attrs.to_vec()); both
} else {
attrs.to_vec()
};
merged_attrs.clean(cx) merged_attrs.clean(cx)
} }