diff options
| author | HampusM <hampus@hampusmat.com> | 2025-02-09 18:41:26 +0100 | 
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2025-02-09 18:41:26 +0100 | 
| commit | 2a8718f7c671ab1fc5e38340b467e2bd77f16cc0 (patch) | |
| tree | 15d2eba5c57b484c89d3f5e11fe41deebbd1f92e | |
| parent | c06d59ffa09e22a98647f5104944e1c13b161963 (diff) | |
perf(ecs): replace component::Sequence::into_vec fn with into_array
| -rw-r--r-- | ecs/src/actions.rs | 4 | ||||
| -rw-r--r-- | ecs/src/component.rs | 16 | ||||
| -rw-r--r-- | ecs/src/lib.rs | 2 | ||||
| -rw-r--r-- | ecs/src/util.rs | 1 | 
4 files changed, 15 insertions, 8 deletions
| diff --git a/ecs/src/actions.rs b/ecs/src/actions.rs index 3988a77..89fd84a 100644 --- a/ecs/src/actions.rs +++ b/ecs/src/actions.rs @@ -24,7 +24,7 @@ impl<'world> Actions<'world>      pub fn spawn<Comps: ComponentSequence>(&mut self, components: Comps)      {          self.action_queue.push(Action::Spawn( -            components.into_vec(), +            components.into_array().into(),              EventIds { ids: Comps::added_event_ids() },          ));      } @@ -50,7 +50,7 @@ impl<'world> Actions<'world>          self.action_queue.push(Action::AddComponents(              entity_uid, -            components.into_vec(), +            components.into_array().into(),              EventIds { ids: Comps::added_event_ids() },          ));      } diff --git a/ecs/src/component.rs b/ecs/src/component.rs index f5aa0d1..b2ecf80 100644 --- a/ecs/src/component.rs +++ b/ecs/src/component.rs @@ -167,7 +167,9 @@ pub trait Sequence      /// The number of components in this component sequence.      const COUNT: usize; -    fn into_vec(self) -> Vec<Box<dyn Component>>; +    type Array: Array<Box<dyn Component>>; + +    fn into_array(self) -> Self::Array;      fn metadata() -> impl Array<Metadata>; @@ -277,9 +279,11 @@ macro_rules! inner {              {                  const COUNT: usize = $c + 1; -                fn into_vec(self) -> Vec<Box<dyn Component>> +                type Array = [Box<dyn Component>; $c + 1]; + +                fn into_array(self) -> Self::Array                  { -                    Vec::from_iter([#(Box::new(self.I) as Box<dyn Component>,)*]) +                    [#(Box::new(self.I) as Box<dyn Component>,)*]                  }                  fn metadata() -> impl Array<Metadata> @@ -356,11 +360,13 @@ seq!(C in 0..=16 {  impl Sequence for ()  { +    type Array = [Box<dyn Component>; 0]; +      const COUNT: usize = 0; -    fn into_vec(self) -> Vec<Box<dyn Component>> +    fn into_array(self) -> Self::Array      { -        Vec::new() +        []      }      fn metadata() -> impl Array<Metadata> diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs index ae3e191..72b5cf9 100644 --- a/ecs/src/lib.rs +++ b/ecs/src/lib.rs @@ -115,7 +115,7 @@ impl World              .component_storage              .write_nonblock()              .expect("Failed to acquire read-write component storage lock") -            .push_entity(entity_uid, components.into_vec()) +            .push_entity(entity_uid, components.into_array().into())          {              tracing::error!("Failed to create entity: {err}"); diff --git a/ecs/src/util.rs b/ecs/src/util.rs index 4ba8597..0273b18 100644 --- a/ecs/src/util.rs +++ b/ecs/src/util.rs @@ -4,6 +4,7 @@ pub trait Array<Item>:      AsRef<[Item]>      + AsMut<[Item]>      + IntoIterator<Item = Item> +    + Into<Vec<Item>>      + Sortable<Item = Item>      + sealed::Sealed  { | 
