Skip to content

Commit c142f40

Browse files
Avoid repeated calls to validate_world in Query::get_multiple
1 parent be22235 commit c142f40

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

crates/bevy_ecs/src/query/state.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,15 @@ where
193193
) -> Result<[<Q::ReadOnlyFetch as Fetch<'w, 's>>::Item; N], QueryEntityError> {
194194
self.update_archetypes(world);
195195

196-
self.get_multiple_read_only_manual(
197-
world,
198-
entities,
199-
world.last_change_tick(),
200-
world.read_change_tick(),
201-
)
196+
// SAFE: update_archetypes validates the `World` matches
197+
unsafe {
198+
self.get_multiple_read_only_manual(
199+
world,
200+
entities,
201+
world.last_change_tick(),
202+
world.read_change_tick(),
203+
)
204+
}
202205
}
203206

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

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

372380
// SAFE: fetch is read-only
381+
// and world must be validated
373382
let array_of_results = unsafe {
374383
entities.map(|entity| {
375384
self.get_unchecked_manual::<Q::ReadOnlyFetch>(

0 commit comments

Comments
 (0)