Skip to content

Commit 8d51f4a

Browse files
committed
Remove useless access to archetype in UnsafeWorldCell::fetch_table (#7665)
# Objective - #6402 changed `World::fetch_table` (now `UnsafeWorldCell::fetch_table`) to access the archetype in order to get the `table_id` and `table_row` of the entity involved. However this is useless since those were already present in the `EntityLocation` - Moreover it's useless for `UnsafeWorldCell::fetch_table` to return the `TableRow` too, since the caller must already have access to the `EntityLocation` which contains the `TableRow`. - The result is that `UnsafeWorldCell::fetch_table` now only does 2 memory fetches instead of 4. ## Solution - Revert the changes to the implementation of `UnsafeWorldCell::fetch_table` made in #6402
1 parent 11a7ff2 commit 8d51f4a

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

crates/bevy_ecs/src/world/unsafe_world_cell.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
},
1111
entity::{Entities, Entity, EntityLocation},
1212
prelude::Component,
13-
storage::{Column, ComponentSparseSet, TableRow},
13+
storage::{Column, ComponentSparseSet},
1414
system::Resource,
1515
};
1616
use bevy_ptr::Ptr;
@@ -754,14 +754,10 @@ impl<'w> UnsafeWorldCell<'w> {
754754
self,
755755
location: EntityLocation,
756756
component_id: ComponentId,
757-
) -> Option<(&'w Column, TableRow)> {
758-
let archetype = &self.archetypes()[location.archetype_id];
757+
) -> Option<&'w Column> {
759758
// SAFETY: caller ensures returned data is not misused and we have not created any borrows
760759
// of component/resource data
761-
let table = &unsafe { self.unsafe_world() }.storages.tables[archetype.table_id()];
762-
let components = table.get_column(component_id)?;
763-
let table_row = archetype.entity_table_row(location.archetype_row);
764-
Some((components, table_row))
760+
unsafe { self.unsafe_world() }.storages.tables[location.table_id].get_column(component_id)
765761
}
766762

767763
#[inline]
@@ -799,9 +795,9 @@ unsafe fn get_component(
799795
// SAFETY: component_id exists and is therefore valid
800796
match storage_type {
801797
StorageType::Table => {
802-
let (components, table_row) = world.fetch_table(location, component_id)?;
798+
let components = world.fetch_table(location, component_id)?;
803799
// SAFETY: archetypes only store valid table_rows and caller ensure aliasing rules
804-
Some(components.get_data_unchecked(table_row))
800+
Some(components.get_data_unchecked(location.table_row))
805801
}
806802
StorageType::SparseSet => world.fetch_sparse_set(component_id)?.get(entity),
807803
}
@@ -825,14 +821,14 @@ unsafe fn get_component_and_ticks(
825821
) -> Option<(Ptr<'_>, TickCells<'_>)> {
826822
match storage_type {
827823
StorageType::Table => {
828-
let (components, table_row) = world.fetch_table(location, component_id)?;
824+
let components = world.fetch_table(location, component_id)?;
829825

830826
// SAFETY: archetypes only store valid table_rows and caller ensure aliasing rules
831827
Some((
832-
components.get_data_unchecked(table_row),
828+
components.get_data_unchecked(location.table_row),
833829
TickCells {
834-
added: components.get_added_ticks_unchecked(table_row),
835-
changed: components.get_changed_ticks_unchecked(table_row),
830+
added: components.get_added_ticks_unchecked(location.table_row),
831+
changed: components.get_changed_ticks_unchecked(location.table_row),
836832
},
837833
))
838834
}
@@ -859,9 +855,9 @@ unsafe fn get_ticks(
859855
) -> Option<ComponentTicks> {
860856
match storage_type {
861857
StorageType::Table => {
862-
let (components, table_row) = world.fetch_table(location, component_id)?;
858+
let components = world.fetch_table(location, component_id)?;
863859
// SAFETY: archetypes only store valid table_rows and caller ensure aliasing rules
864-
Some(components.get_ticks_unchecked(table_row))
860+
Some(components.get_ticks_unchecked(location.table_row))
865861
}
866862
StorageType::SparseSet => world.fetch_sparse_set(component_id)?.get_ticks(entity),
867863
}

0 commit comments

Comments
 (0)