Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Skip empty archetypes and tables when iterating over queries #4724

Closed
wants to merge 15 commits into from
Prev Previous commit
Next Next commit
Merge branch 'main' into skip-empty
  • Loading branch information
james7132 committed Jun 30, 2022
commit 74cf8a438113c9aad7ae9ff90d950aeaf645e39e
41 changes: 5 additions & 36 deletions crates/bevy_ecs/src/query/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,11 @@ where
#[inline(always)]
fn next(&mut self) -> Option<Self::Item> {
unsafe {
if QF::IS_DENSE && <QueryFetch<'static, F>>::IS_DENSE {
loop {
if self.current_index == self.current_len {
let table_id = self.table_id_iter.next()?;
let table = &self.tables[*table_id];
if table.is_empty() {
continue;
}

self.fetch.set_table(&self.query_state.fetch_state, table);
self.filter.set_table(&self.query_state.filter_state, table);
self.current_len = table.len();
self.current_index = 0;
}
for entity in self.entity_iter.by_ref() {
let location = match self.entities.get(*entity.borrow()) {
Some(location) => location,
None => continue,
};

if !self
.query_state
Expand All @@ -173,28 +164,6 @@ where
{
continue;
}
} else {
loop {
if self.current_index == self.current_len {
let archetype_id = self.archetype_id_iter.next()?;
let archetype = &self.archetypes[*archetype_id];
if archetype.is_empty() {
continue;
}

self.fetch.set_archetype(
&self.query_state.fetch_state,
archetype,
self.tables,
);
self.filter.set_archetype(
&self.query_state.filter_state,
archetype,
self.tables,
);
self.current_len = archetype.len();
self.current_index = 0;
}

let archetype = &self.archetypes[location.archetype_id];

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.