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
This commit is contained in:
		
							parent
							
								
									11a7ff2645
								
							
						
					
					
						commit
						8d51f4a2a5
					
				| @ -10,7 +10,7 @@ use crate::{ | |||||||
|     }, |     }, | ||||||
|     entity::{Entities, Entity, EntityLocation}, |     entity::{Entities, Entity, EntityLocation}, | ||||||
|     prelude::Component, |     prelude::Component, | ||||||
|     storage::{Column, ComponentSparseSet, TableRow}, |     storage::{Column, ComponentSparseSet}, | ||||||
|     system::Resource, |     system::Resource, | ||||||
| }; | }; | ||||||
| use bevy_ptr::Ptr; | use bevy_ptr::Ptr; | ||||||
| @ -754,14 +754,10 @@ impl<'w> UnsafeWorldCell<'w> { | |||||||
|         self, |         self, | ||||||
|         location: EntityLocation, |         location: EntityLocation, | ||||||
|         component_id: ComponentId, |         component_id: ComponentId, | ||||||
|     ) -> Option<(&'w Column, TableRow)> { |     ) -> Option<&'w Column> { | ||||||
|         let archetype = &self.archetypes()[location.archetype_id]; |  | ||||||
|         // SAFETY: caller ensures returned data is not misused and we have not created any borrows
 |         // SAFETY: caller ensures returned data is not misused and we have not created any borrows
 | ||||||
|         // of component/resource data
 |         // of component/resource data
 | ||||||
|         let table = &unsafe { self.unsafe_world() }.storages.tables[archetype.table_id()]; |         unsafe { self.unsafe_world() }.storages.tables[location.table_id].get_column(component_id) | ||||||
|         let components = table.get_column(component_id)?; |  | ||||||
|         let table_row = archetype.entity_table_row(location.archetype_row); |  | ||||||
|         Some((components, table_row)) |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[inline] |     #[inline] | ||||||
| @ -799,9 +795,9 @@ unsafe fn get_component( | |||||||
|     // SAFETY: component_id exists and is therefore valid
 |     // SAFETY: component_id exists and is therefore valid
 | ||||||
|     match storage_type { |     match storage_type { | ||||||
|         StorageType::Table => { |         StorageType::Table => { | ||||||
|             let (components, table_row) = world.fetch_table(location, component_id)?; |             let components = world.fetch_table(location, component_id)?; | ||||||
|             // SAFETY: archetypes only store valid table_rows and caller ensure aliasing rules
 |             // SAFETY: archetypes only store valid table_rows and caller ensure aliasing rules
 | ||||||
|             Some(components.get_data_unchecked(table_row)) |             Some(components.get_data_unchecked(location.table_row)) | ||||||
|         } |         } | ||||||
|         StorageType::SparseSet => world.fetch_sparse_set(component_id)?.get(entity), |         StorageType::SparseSet => world.fetch_sparse_set(component_id)?.get(entity), | ||||||
|     } |     } | ||||||
| @ -825,14 +821,14 @@ unsafe fn get_component_and_ticks( | |||||||
| ) -> Option<(Ptr<'_>, TickCells<'_>)> { | ) -> Option<(Ptr<'_>, TickCells<'_>)> { | ||||||
|     match storage_type { |     match storage_type { | ||||||
|         StorageType::Table => { |         StorageType::Table => { | ||||||
|             let (components, table_row) = world.fetch_table(location, component_id)?; |             let components = world.fetch_table(location, component_id)?; | ||||||
| 
 | 
 | ||||||
|             // SAFETY: archetypes only store valid table_rows and caller ensure aliasing rules
 |             // SAFETY: archetypes only store valid table_rows and caller ensure aliasing rules
 | ||||||
|             Some(( |             Some(( | ||||||
|                 components.get_data_unchecked(table_row), |                 components.get_data_unchecked(location.table_row), | ||||||
|                 TickCells { |                 TickCells { | ||||||
|                     added: components.get_added_ticks_unchecked(table_row), |                     added: components.get_added_ticks_unchecked(location.table_row), | ||||||
|                     changed: components.get_changed_ticks_unchecked(table_row), |                     changed: components.get_changed_ticks_unchecked(location.table_row), | ||||||
|                 }, |                 }, | ||||||
|             )) |             )) | ||||||
|         } |         } | ||||||
| @ -859,9 +855,9 @@ unsafe fn get_ticks( | |||||||
| ) -> Option<ComponentTicks> { | ) -> Option<ComponentTicks> { | ||||||
|     match storage_type { |     match storage_type { | ||||||
|         StorageType::Table => { |         StorageType::Table => { | ||||||
|             let (components, table_row) = world.fetch_table(location, component_id)?; |             let components = world.fetch_table(location, component_id)?; | ||||||
|             // SAFETY: archetypes only store valid table_rows and caller ensure aliasing rules
 |             // SAFETY: archetypes only store valid table_rows and caller ensure aliasing rules
 | ||||||
|             Some(components.get_ticks_unchecked(table_row)) |             Some(components.get_ticks_unchecked(location.table_row)) | ||||||
|         } |         } | ||||||
|         StorageType::SparseSet => world.fetch_sparse_set(component_id)?.get_ticks(entity), |         StorageType::SparseSet => world.fetch_sparse_set(component_id)?.get_ticks(entity), | ||||||
|     } |     } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Giacomo Stevanato
						Giacomo Stevanato