Skip to content

Commit

Permalink
reduce the number of duplicate accesses for Or and AnyOf
Browse files Browse the repository at this point in the history
  • Loading branch information
cBournhonesque committed Jun 26, 2024
1 parent 2aebf38 commit 8020fd4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions crates/bevy_ecs/src/query/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1862,17 +1862,18 @@ macro_rules! impl_anytuple_fetch {
}

fn update_component_access(state: &Self::State, _access: &mut FilteredAccess<ComponentId>) {
// update the access (add the read/writes)
<($(Option<$name>,)*)>::update_component_access(state, _access);

// update the filters (Or<(With<$name>,)>)
let ($($name,)*) = state;
let mut _new_access = FilteredAccess::default();
$(
// we use an intermediate empty access because we only want to update the filters, not the access
let mut intermediate = FilteredAccess::default();
let mut intermediate = _access.clone();
$name::update_component_access($name, &mut intermediate);
_access.append_or(&intermediate);
_new_access.append_or(&intermediate);
)*
_access.filter_sets = _new_access.filter_sets;

<($(Option<$name>,)*)>::update_component_access(state, _access);
}
#[allow(unused_variables)]
fn init_state(world: &mut World) -> Self::State {
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/query/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ macro_rules! impl_or_query_filter {
fn update_component_access(state: &Self::State, access: &mut FilteredAccess<ComponentId>) {
let ($($filter,)*) = state;

let mut _new_access = access.clone();
let mut _new_access = FilteredAccess::default();
$(
let mut intermediate = access.clone();
$filter::update_component_access($filter, &mut intermediate);
Expand Down

0 comments on commit 8020fd4

Please sign in to comment.