Skip to content

Commit 1766850

Browse files
committed
Use smallvec
Signed-off-by: Alex Saveau <[email protected]>
1 parent 184d5a5 commit 1766850

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ bevy_ui = ["bevy/bevy_ui", "bevy/bevy_text", "bevy/bevy_render"]
2222
[dependencies]
2323
interpolation = "0.2"
2424
bevy = { version = "0.7", default-features = false }
25+
smallvec = "1.8.0"
2526

2627
[dev-dependencies]
2728
bevy-inspector-egui = "0.10"

src/tweenable.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::time::Duration;
22

33
use bevy::prelude::*;
4+
use smallvec::{smallvec, SmallVec};
45

56
use 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.
475476
pub 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.
623625
pub 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> {
630632
impl<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

Comments
 (0)