1
Fork 0

Rollup merge of #52703 - ljedrz:vec_improvements, r=nikomatsakis

Improve a few vectors - calculate capacity or build from iterators

Collecting from iterators improves readability and tailoring vector capacities should be beneficial in terms of performance.
This commit is contained in:
kennytm 2018-07-28 16:24:57 +08:00 committed by GitHub
commit 7da22148ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 21 deletions

View file

@ -632,15 +632,14 @@ impl MultiSpan {
/// `SpanLabel` instances with empty labels.
pub fn span_labels(&self) -> Vec<SpanLabel> {
let is_primary = |span| self.primary_spans.contains(&span);
let mut span_labels = vec![];
for &(span, ref label) in &self.span_labels {
span_labels.push(SpanLabel {
let mut span_labels = self.span_labels.iter().map(|&(span, ref label)|
SpanLabel {
span,
is_primary: is_primary(span),
label: Some(label.clone())
});
}
}
).collect::<Vec<_>>();
for &span in &self.primary_spans {
if !span_labels.iter().any(|sl| sl.span == span) {