ecs: slightly improve perf with inlining changes
This commit is contained in:
parent
a7bab755ee
commit
88781007b0
@ -106,6 +106,7 @@ impl Archetype {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
|
#[inline]
|
||||||
pub fn get<T: Component>(&self) -> Option<NonNull<T>> {
|
pub fn get<T: Component>(&self) -> Option<NonNull<T>> {
|
||||||
let state = self.state.get(&TypeId::of::<T>())?;
|
let state = self.state.get(&TypeId::of::<T>())?;
|
||||||
Some(unsafe {
|
Some(unsafe {
|
||||||
|
|||||||
@ -72,9 +72,11 @@ impl Query for Entity {
|
|||||||
|
|
||||||
impl<'a> Fetch<'a> for EntityFetch {
|
impl<'a> Fetch<'a> for EntityFetch {
|
||||||
type Item = Entity;
|
type Item = Entity;
|
||||||
|
#[inline]
|
||||||
fn access(_archetype: &Archetype) -> Option<Access> {
|
fn access(_archetype: &Archetype) -> Option<Access> {
|
||||||
Some(Access::Iterate)
|
Some(Access::Iterate)
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
fn borrow(_archetype: &Archetype) {}
|
fn borrow(_archetype: &Archetype) {}
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
|
unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
|
||||||
@ -82,6 +84,7 @@ impl<'a> Fetch<'a> for EntityFetch {
|
|||||||
archetype.entities().as_ptr().add(offset),
|
archetype.entities().as_ptr().add(offset),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
fn release(_archetype: &Archetype) {}
|
fn release(_archetype: &Archetype) {}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -152,7 +155,6 @@ impl<'a, T: Component> Fetch<'a> for FetchWrite<T> {
|
|||||||
fn borrow(archetype: &Archetype) {
|
fn borrow(archetype: &Archetype) {
|
||||||
archetype.borrow_mut::<T>();
|
archetype.borrow_mut::<T>();
|
||||||
}
|
}
|
||||||
#[inline]
|
|
||||||
unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
|
unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
|
||||||
archetype
|
archetype
|
||||||
.get::<T>()
|
.get::<T>()
|
||||||
@ -162,7 +164,6 @@ impl<'a, T: Component> Fetch<'a> for FetchWrite<T> {
|
|||||||
archetype.release_mut::<T>();
|
archetype.release_mut::<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
unsafe fn next(&mut self) -> &'a mut T {
|
unsafe fn next(&mut self) -> &'a mut T {
|
||||||
let x = self.0.as_ptr();
|
let x = self.0.as_ptr();
|
||||||
self.0 = NonNull::new_unchecked(x.add(1));
|
self.0 = NonNull::new_unchecked(x.add(1));
|
||||||
@ -517,7 +518,6 @@ struct ChunkIter<Q: Query> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<Q: Query> ChunkIter<Q> {
|
impl<Q: Query> ChunkIter<Q> {
|
||||||
#[inline]
|
|
||||||
unsafe fn next<'a, 'w>(&mut self) -> Option<<Q::Fetch as Fetch<'a>>::Item> {
|
unsafe fn next<'a, 'w>(&mut self) -> Option<<Q::Fetch as Fetch<'a>>::Item> {
|
||||||
if self.len == 0 {
|
if self.len == 0 {
|
||||||
return None;
|
return None;
|
||||||
|
|||||||
@ -53,6 +53,7 @@ where
|
|||||||
self.thread_local_execution
|
self.thread_local_execution
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn run(&mut self, world: &World, resources: &Resources) {
|
fn run(&mut self, world: &World, resources: &Resources) {
|
||||||
(self.func)(world, resources, &self.archetype_access, &mut self.state);
|
(self.func)(world, resources, &self.archetype_access, &mut self.state);
|
||||||
}
|
}
|
||||||
@ -102,9 +103,8 @@ macro_rules! impl_into_foreach_system {
|
|||||||
<<($($resource,)*) as ResourceQuery>::Fetch as FetchResource>::borrow(&resources.resource_archetypes);
|
<<($($resource,)*) as ResourceQuery>::Fetch as FetchResource>::borrow(&resources.resource_archetypes);
|
||||||
{
|
{
|
||||||
let ($($resource,)*) = resources.query_system::<($($resource,)*)>(id);
|
let ($($resource,)*) = resources.query_system::<($($resource,)*)>(id);
|
||||||
let commands = state.clone();
|
|
||||||
for ($($component,)*) in world.query::<($($component,)*)>().iter() {
|
for ($($component,)*) in world.query::<($($component,)*)>().iter() {
|
||||||
fn_call!(self, ($($commands, commands)*), ($($resource),*), ($($component),*))
|
fn_call!(self, ($($commands, state)*), ($($resource),*), ($($component),*))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
<<($($resource,)*) as ResourceQuery>::Fetch as FetchResource>::release(&resources.resource_archetypes);
|
<<($($resource,)*) as ResourceQuery>::Fetch as FetchResource>::release(&resources.resource_archetypes);
|
||||||
@ -242,7 +242,7 @@ macro_rules! impl_into_query_system {
|
|||||||
i += 1;
|
i += 1;
|
||||||
)*
|
)*
|
||||||
|
|
||||||
let commands = state.commands.clone();
|
let commands = &state.commands;
|
||||||
fn_call!(self, ($($commands, commands)*), ($($resource),*), ($($query),*))
|
fn_call!(self, ($($commands, commands)*), ($($resource),*), ($($query),*))
|
||||||
}
|
}
|
||||||
<<($($resource,)*) as ResourceQuery>::Fetch as FetchResource>::release(&resources.resource_archetypes);
|
<<($($resource,)*) as ResourceQuery>::Fetch as FetchResource>::release(&resources.resource_archetypes);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user