Skip to content

Commit

Permalink
Avoid repeated calls to validate_world in Query::get_multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-i-cecile committed Mar 30, 2022
1 parent be22235 commit c142f40
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions crates/bevy_ecs/src/query/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,15 @@ where
) -> Result<[<Q::ReadOnlyFetch as Fetch<'w, 's>>::Item; N], QueryEntityError> {
self.update_archetypes(world);

self.get_multiple_read_only_manual(
world,
entities,
world.last_change_tick(),
world.read_change_tick(),
)
// SAFE: update_archetypes validates the `World` matches
unsafe {
self.get_multiple_read_only_manual(
world,
entities,
world.last_change_tick(),
world.read_change_tick(),
)
}
}

/// Gets the query result for the given [`World`] and [`Entity`].
Expand Down Expand Up @@ -360,7 +363,12 @@ where

/// Gets the read-only query results for the given [`World`] and array of [`Entity`], where the last change and
/// the current change tick are given.
pub(crate) fn get_multiple_read_only_manual<'s, 'w, const N: usize>(
///
/// # Safety
///
/// This must be called on the same `World` that the `Query` was generated from:
/// use `QueryState::validate_world` to verify this.
pub(crate) unsafe fn get_multiple_read_only_manual<'s, 'w, const N: usize>(
&'s self,
world: &'w World,
entities: [Entity; N],
Expand All @@ -370,6 +378,7 @@ where
self.validate_world(world);

// SAFE: fetch is read-only
// and world must be validated
let array_of_results = unsafe {
entities.map(|entity| {
self.get_unchecked_manual::<Q::ReadOnlyFetch>(
Expand Down

0 comments on commit c142f40

Please sign in to comment.