11use std:: time:: Duration ;
22
33use bevy:: prelude:: * ;
4+ use smallvec:: { smallvec, SmallVec } ;
45
56use crate :: { EaseMethod , Lens , TweeningDirection , TweeningType } ;
67
@@ -473,7 +474,7 @@ impl<T> Tweenable<T> for Tween<T> {
473474
474475/// A sequence of tweens played back in order one after the other.
475476pub struct Sequence < T > {
476- tweens : Vec < BoxedTweenable < T > > ,
477+ tweens : SmallVec < [ BoxedTweenable < T > ; 3 ] > ,
477478 index : usize ,
478479 duration : Duration ,
479480 time : Duration ,
@@ -485,7 +486,7 @@ impl<T> Sequence<T> {
485486 ///
486487 /// This method panics if the input collection is empty.
487488 pub fn new ( items : impl IntoIterator < Item = impl Into < BoxedTweenable < T > > > ) -> Self {
488- let tweens: Vec < _ > = items. into_iter ( ) . map ( Into :: into) . collect ( ) ;
489+ let tweens: SmallVec < [ _ ; 3 ] > = items. into_iter ( ) . map ( Into :: into) . collect ( ) ;
489490 assert ! ( !tweens. is_empty( ) ) ;
490491 let duration = tweens. iter ( ) . map ( |t| t. duration ( ) ) . sum ( ) ;
491492 Sequence {
@@ -500,8 +501,9 @@ impl<T> Sequence<T> {
500501 /// Create a new sequence containing a single tween.
501502 pub fn from_single ( tween : impl Tweenable < T > + Send + Sync + ' static ) -> Self {
502503 let duration = tween. duration ( ) ;
504+ let boxed: BoxedTweenable < T > = Box :: new ( tween) ;
503505 Sequence {
504- tweens : vec ! [ Box :: new ( tween ) ] ,
506+ tweens : smallvec ! [ boxed ] ,
505507 index : 0 ,
506508 duration,
507509 time : Duration :: ZERO ,
@@ -512,7 +514,7 @@ impl<T> Sequence<T> {
512514 /// Create a new sequence with the specified capacity.
513515 pub fn with_capacity ( capacity : usize ) -> Self {
514516 Sequence {
515- tweens : Vec :: with_capacity ( capacity) ,
517+ tweens : SmallVec :: with_capacity ( capacity) ,
516518 index : 0 ,
517519 duration : Duration :: ZERO ,
518520 time : Duration :: ZERO ,
@@ -621,7 +623,7 @@ impl<T> Tweenable<T> for Sequence<T> {
621623
622624/// A collection of [`Tweenable`] executing in parallel.
623625pub struct Tracks < T > {
624- tracks : Vec < BoxedTweenable < T > > ,
626+ tracks : SmallVec < [ BoxedTweenable < T > ; 3 ] > ,
625627 duration : Duration ,
626628 time : Duration ,
627629 times_completed : u32 ,
@@ -630,7 +632,7 @@ pub struct Tracks<T> {
630632impl < T > Tracks < T > {
631633 /// Create a new [`Tracks`] from an iterator over a collection of [`Tweenable`].
632634 pub fn new ( items : impl IntoIterator < Item = impl Into < BoxedTweenable < T > > > ) -> Self {
633- let tracks: Vec < _ > = items. into_iter ( ) . map ( Into :: into) . collect ( ) ;
635+ let tracks: SmallVec < [ _ ; 3 ] > = items. into_iter ( ) . map ( Into :: into) . collect ( ) ;
634636 let duration = tracks. iter ( ) . map ( |t| t. duration ( ) ) . max ( ) . unwrap ( ) ;
635637 Tracks {
636638 tracks,
0 commit comments