From b8417d20765755cfa2cecacb11c77e3abbafd546 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 24 May 2024 19:00:38 +0200 Subject: fix(ecs): prevent unnecessary locking in Sequence::from_components --- ecs/src/component.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'ecs/src/component.rs') diff --git a/ecs/src/component.rs b/ecs/src/component.rs index 604f54d..9310995 100644 --- a/ecs/src/component.rs +++ b/ecs/src/component.rs @@ -3,9 +3,10 @@ use std::fmt::Debug; use seq_macro::seq; -use crate::lock::{Lock, WriteGuard}; +use crate::lock::WriteGuard; use crate::system::{ComponentRefMut, Input as SystemInput}; use crate::type_name::TypeName; +use crate::EntityComponent; pub mod local; @@ -112,7 +113,7 @@ pub trait Sequence fn type_ids() -> Vec<(TypeId, IsOptional)>; fn from_components<'component>( - components: impl Iterator>>, + components: impl Iterator, ) -> Self::Refs<'component>; } @@ -180,7 +181,7 @@ macro_rules! inner { } fn from_components<'component>( - components: impl Iterator>>, + components: impl Iterator, ) -> Self::Refs<'component> { #( @@ -188,12 +189,14 @@ macro_rules! inner { )* for comp in components { - let comp_ref = comp - .write_nonblock() - .expect("Failed to acquire read-write component lock"); - #( - if comp_ref.is::() { + if comp.id == TypeId::of::() { + let comp_ref = comp.component + .write_nonblock() + .expect( + "Failed to acquire read-write component lock" + ); + comp_~I = Some(comp_ref); continue; } -- cgit v1.2.3-18-g5258