Skip to content

Commit

Permalink
Implement smallvec optimization for SpanScopeFromRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
nightkr committed Jun 9, 2021
1 parent 0e45e83 commit 5c379fb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tracing-subscriber/src/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,12 @@ where
/// Flips the order of the iterator, so that it is ordered from root to leaf.
#[allow(clippy::wrong_self_convention)]
pub fn from_root(self) -> SpanScopeFromRoot<'a, R> {
#[cfg(feature = "smallvec")]
type Buf<T> = smallvec::SmallVec<T>;
#[cfg(not(feature = "smallvec"))]
type Buf<T> = Vec<T>;
SpanScopeFromRoot {
spans: self.collect::<Vec<_>>().into_iter().rev(),
spans: self.collect::<Buf<_>>().into_iter().rev(),
}
}
}
Expand All @@ -213,6 +217,9 @@ pub struct SpanScopeFromRoot<'a, R>
where
R: LookupSpan<'a>,
{
#[cfg(feature = "smallvec")]
spans: std::iter::Rev<smallvec::IntoIter<SpanRefVecArray<'a, R>>>,
#[cfg(not(feature = "smallvec"))]
spans: std::iter::Rev<std::vec::IntoIter<SpanRef<'a, R>>>,
}

Expand Down

0 comments on commit 5c379fb

Please sign in to comment.