mirror of
https://github.com/bevyengine/bevy
synced 2025-02-16 22:18:33 +00:00
inline iter_combinations (#14680)
# Objective - fix #14679 - bevy's performance highly depends on compiler optimization,inline hot function could greatly help compiler to optimize our program
This commit is contained in:
parent
23e87270df
commit
e490b919df
2 changed files with 8 additions and 13 deletions
|
@ -1436,6 +1436,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, const K: usize> QueryCombinationIter<
|
|||
last_run: Tick,
|
||||
this_run: Tick,
|
||||
) -> Self {
|
||||
assert!(K != 0, "K should not equal to zero");
|
||||
// Initialize array with cursors.
|
||||
// There is no FromIterator on arrays, so instead initialize it manually with MaybeUninit
|
||||
|
||||
|
@ -1443,14 +1444,12 @@ impl<'w, 's, D: QueryData, F: QueryFilter, const K: usize> QueryCombinationIter<
|
|||
let ptr = array
|
||||
.as_mut_ptr()
|
||||
.cast::<QueryIterationCursor<'w, 's, D, F>>();
|
||||
if K != 0 {
|
||||
ptr.write(QueryIterationCursor::init(
|
||||
world,
|
||||
query_state,
|
||||
last_run,
|
||||
this_run,
|
||||
));
|
||||
}
|
||||
ptr.write(QueryIterationCursor::init(
|
||||
world,
|
||||
query_state,
|
||||
last_run,
|
||||
this_run,
|
||||
));
|
||||
for slot in (1..K).map(|offset| ptr.add(offset)) {
|
||||
slot.write(QueryIterationCursor::init_empty(
|
||||
world,
|
||||
|
@ -1475,11 +1474,8 @@ impl<'w, 's, D: QueryData, F: QueryFilter, const K: usize> QueryCombinationIter<
|
|||
/// references to the same component, leading to unique reference aliasing.
|
||||
///.
|
||||
/// It is always safe for shared access.
|
||||
#[inline]
|
||||
unsafe fn fetch_next_aliased_unchecked(&mut self) -> Option<[D::Item<'w>; K]> {
|
||||
if K == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
// PERF: can speed up the following code using `cursor.remaining()` instead of `next_item.is_none()`
|
||||
// when D::IS_ARCHETYPAL && F::IS_ARCHETYPAL
|
||||
//
|
||||
|
|
|
@ -146,7 +146,6 @@ mod tests {
|
|||
assert_all_exact_sizes_iterator_equal(query.iter(world), expected_size, 5, query_type);
|
||||
|
||||
let expected = expected_size;
|
||||
assert_combination::<D, F, 0>(world, choose(expected, 0));
|
||||
assert_combination::<D, F, 1>(world, choose(expected, 1));
|
||||
assert_combination::<D, F, 2>(world, choose(expected, 2));
|
||||
assert_combination::<D, F, 5>(world, choose(expected, 5));
|
||||
|
|
Loading…
Add table
Reference in a new issue