Skip to content

Commit

Permalink
move fetch_table and fetch_sparse_set to World
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobhellermann committed Dec 17, 2022
1 parent a71bdda commit cd69b55
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ impl World {
) -> Option<(Ptr<'_>, TickCells<'_>)> {
match storage_type {
StorageType::Table => {
let (components, table_row) = fetch_table(self, location, component_id)?;
let (components, table_row) = self.fetch_table(location, component_id)?;

// SAFETY: archetypes only store valid table_rows and caller ensure aliasing rules
Some((
Expand All @@ -1597,7 +1597,7 @@ impl World {
},
))
}
StorageType::SparseSet => fetch_sparse_set(self, component_id)?.get_with_ticks(entity),
StorageType::SparseSet => self.fetch_sparse_set(component_id)?.get_with_ticks(entity),
}
}

Expand Down Expand Up @@ -1640,11 +1640,11 @@ impl World {
// SAFETY: component_id exists and is therefore valid
match storage_type {
StorageType::Table => {
let (components, table_row) = fetch_table(self, location, component_id)?;
let (components, table_row) = self.fetch_table(location, component_id)?;
// SAFETY: archetypes only store valid table_rows and caller ensure aliasing rules
Some(components.get_data_unchecked(table_row))
}
StorageType::SparseSet => fetch_sparse_set(self, component_id)?.get(entity),
StorageType::SparseSet => self.fetch_sparse_set(component_id)?.get(entity),
}
}

Expand Down Expand Up @@ -1686,31 +1686,31 @@ impl World {
) -> Option<ComponentTicks> {
match storage_type {
StorageType::Table => {
let (components, table_row) = fetch_table(self, location, component_id)?;
let (components, table_row) = self.fetch_table(location, component_id)?;
// SAFETY: archetypes only store valid table_rows and caller ensure aliasing rules
Some(components.get_ticks_unchecked(table_row))
}
StorageType::SparseSet => fetch_sparse_set(self, component_id)?.get_ticks(entity),
StorageType::SparseSet => self.fetch_sparse_set(component_id)?.get_ticks(entity),
}
}
}

#[inline]
unsafe fn fetch_table(
world: &World,
location: EntityLocation,
component_id: ComponentId,
) -> Option<(&Column, TableRow)> {
let archetype = &world.archetypes[location.archetype_id];
let table = &world.storages.tables[archetype.table_id()];
let components = table.get_column(component_id)?;
let table_row = archetype.entity_table_row(location.archetype_row);
Some((components, table_row))
}
#[inline]
unsafe fn fetch_table(
&self,
location: EntityLocation,
component_id: ComponentId,
) -> Option<(&Column, TableRow)> {
let archetype = &self.archetypes[location.archetype_id];
let table = &self.storages.tables[archetype.table_id()];
let components = table.get_column(component_id)?;
let table_row = archetype.entity_table_row(location.archetype_row);
Some((components, table_row))
}

#[inline]
fn fetch_sparse_set(world: &World, component_id: ComponentId) -> Option<&ComponentSparseSet> {
world.storages.sparse_sets.get(component_id)
#[inline]
fn fetch_sparse_set(&self, component_id: ComponentId) -> Option<&ComponentSparseSet> {
self.storages.sparse_sets.get(component_id)
}
}

impl fmt::Debug for World {
Expand Down

0 comments on commit cd69b55

Please sign in to comment.