From 0004d010da57c1794df0d99017014d4ce11eda18 Mon Sep 17 00:00:00 2001 From: Ellen Date: Thu, 17 Mar 2022 14:34:39 +0000 Subject: [PATCH] yeet --- crates/bevy_ecs/src/system/mod.rs | 4 +-- crates/bevy_ecs/src/system/query.rs | 38 ++++++++++++++------------- crates/bevy_pbr/src/render/mesh.rs | 3 ++- crates/bevy_sprite/src/mesh2d/mesh.rs | 3 ++- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/crates/bevy_ecs/src/system/mod.rs b/crates/bevy_ecs/src/system/mod.rs index f79ab002961720..60339e68cc4a5c 100644 --- a/crates/bevy_ecs/src/system/mod.rs +++ b/crates/bevy_ecs/src/system/mod.rs @@ -804,13 +804,13 @@ mod tests { } fn hold_component<'w>(&mut self, world: &'w World, entity: Entity) -> Holder<'w> { let q = self.state_q.get(world); - let a = q.get(entity).unwrap(); + let a = unsafe { q.get_unchecked(entity) }.unwrap(); Holder { value: a } } fn hold_components<'w>(&mut self, world: &'w World) -> Vec> { let mut components = Vec::new(); let q = self.state_q.get(world); - for a in q.iter() { + for a in unsafe { q.iter_unsafe() } { components.push(Holder { value: a }); } components diff --git a/crates/bevy_ecs/src/system/query.rs b/crates/bevy_ecs/src/system/query.rs index 8d65633de149da..688d520a5f8e36 100644 --- a/crates/bevy_ecs/src/system/query.rs +++ b/crates/bevy_ecs/src/system/query.rs @@ -299,7 +299,7 @@ where /// # bevy_ecs::system::assert_is_system(report_names_system); /// ``` #[inline] - pub fn iter(&'s self) -> QueryIter<'w, 's, Q, Q::ReadOnlyFetch, F> { + pub fn iter(&self) -> QueryIter<'_, 's, Q, Q::ReadOnlyFetch, F> { // SAFE: system runs without conflicts with other systems. // same-system queries have runtime borrow checks when they conflict unsafe { @@ -454,17 +454,19 @@ where /// # bevy_ecs::system::assert_is_system(report_names_system); /// ``` #[inline] - pub fn for_each>::Item)>(&'s self, f: FN) { + pub fn for_each<'this>( + &'this self, + f: impl FnMut(>::Item), + ) { // SAFE: system runs without conflicts with other systems. // same-system queries have runtime borrow checks when they conflict unsafe { - self.state - .for_each_unchecked_manual::( - self.world, - f, - self.last_change_tick, - self.change_tick, - ); + self.state.for_each_unchecked_manual::( + self.world, + f, + self.last_change_tick, + self.change_tick, + ); }; } @@ -524,17 +526,17 @@ where ///* `batch_size` - The number of batches to spawn ///* `f` - The function to run on each item in the query #[inline] - pub fn par_for_each>::Item) + Send + Sync + Clone>( - &'s self, + pub fn par_for_each<'this>( + &'this self, task_pool: &TaskPool, batch_size: usize, - f: FN, + f: impl Fn(>::Item) + Send + Sync + Clone, ) { // SAFE: system runs without conflicts with other systems. same-system queries have runtime // borrow checks when they conflict unsafe { self.state - .par_for_each_unchecked_manual::( + .par_for_each_unchecked_manual::( self.world, task_pool, batch_size, @@ -601,9 +603,9 @@ where /// ``` #[inline] pub fn get( - &'s self, + &self, entity: Entity, - ) -> Result<>::Item, QueryEntityError> { + ) -> Result<>::Item, QueryEntityError> { // SAFE: system runs without conflicts with other systems. // same-system queries have runtime borrow checks when they conflict unsafe { @@ -834,7 +836,7 @@ where /// Panics if the number of query results is not exactly one. Use /// [`get_single`](Self::get_single) to return a `Result` instead of panicking. #[track_caller] - pub fn single(&'s self) -> >::Item { + pub fn single(&self) -> >::Item { self.get_single().unwrap() } @@ -870,8 +872,8 @@ where /// # bevy_ecs::system::assert_is_system(player_scoring_system); /// ``` pub fn get_single( - &'s self, - ) -> Result<>::Item, QuerySingleError> { + &self, + ) -> Result<>::Item, QuerySingleError> { let mut query = self.iter(); let first = query.next(); let extra = query.next().is_some(); diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index 8d00086881215c..475e8f78204332 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -625,7 +625,8 @@ impl EntityRenderCommand for SetMeshViewBindGroup { view_query: SystemParamItem<'w, '_, Self::Param>, pass: &mut TrackedRenderPass<'w>, ) -> RenderCommandResult { - let (view_uniform, view_lights, mesh_view_bind_group) = view_query.get(view).unwrap(); + let (view_uniform, view_lights, mesh_view_bind_group) = + unsafe { view_query.get_unchecked(view) }.unwrap(); pass.set_bind_group( I, &mesh_view_bind_group.value, diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index 2c6e31085130aa..6fc2525b49ef96 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -401,7 +401,8 @@ impl EntityRenderCommand for SetMesh2dViewBindGroup { view_query: SystemParamItem<'w, '_, Self::Param>, pass: &mut TrackedRenderPass<'w>, ) -> RenderCommandResult { - let (view_uniform, mesh2d_view_bind_group) = view_query.get(view).unwrap(); + let (view_uniform, mesh2d_view_bind_group) = + unsafe { view_query.get_unchecked(view) }.unwrap(); pass.set_bind_group(I, &mesh2d_view_bind_group.value, &[view_uniform.offset]); RenderCommandResult::Success