Remove unnecessary branch in query iteration (#12844)
# Objective - Since #10811,Bevy uses `assert `in the hot path of iteration. The `for_each `method has an assert in the outer loop to help the compiler remove unnecessary branching in the internal loop. - However , ` for` style iterations do not receive the same treatment. it still have a branch check in the internal loop, which could potentially hurt performance. ## Solution - use `TableRow::from_u32 ` instead of ` TableRow::from_usize` to avoid unnecessary branch. Before  After ---------------------------------------------------------------------------- 
This commit is contained in:
parent
8092e2c86d
commit
06738bff63
@ -56,7 +56,7 @@ impl TableId {
|
|||||||
/// Will panic if the provided value does not fit within a [`u32`].
|
/// Will panic if the provided value does not fit within a [`u32`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn from_usize(index: usize) -> Self {
|
pub const fn from_usize(index: usize) -> Self {
|
||||||
assert!(index as u32 as usize == index);
|
debug_assert!(index as u32 as usize == index);
|
||||||
Self(index as u32)
|
Self(index as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ impl TableRow {
|
|||||||
/// Will panic if the provided value does not fit within a [`u32`].
|
/// Will panic if the provided value does not fit within a [`u32`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn from_usize(index: usize) -> Self {
|
pub const fn from_usize(index: usize) -> Self {
|
||||||
assert!(index as u32 as usize == index);
|
debug_assert!(index as u32 as usize == index);
|
||||||
Self(index as u32)
|
Self(index as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user