Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxyUwU committed Feb 3, 2023
1 parent e2f5eb5 commit 3a84c74
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions crates/bevy_ecs/src/world/unsafe_world_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ unsafe impl Send for UnsafeWorldCell<'_> {}
unsafe impl Sync for UnsafeWorldCell<'_> {}

impl<'w> UnsafeWorldCell<'w> {
/// Creates a [`UnsafeWorldCell`] that can be used to access everything immutably
pub(crate) fn new_readonly(world: &'w World) -> Self {
UnsafeWorldCell(world as *const World as *mut World, PhantomData)
}

/// Creates [`UnsafeWorldCell`] that can be used to access everything mutably
pub(crate) fn new_mutable(world: &'w mut World) -> Self {
Self(world as *mut World, PhantomData)
}
Expand Down Expand Up @@ -818,24 +820,37 @@ unsafe fn get_ticks(
}

#[inline]
#[allow(unsafe_op_in_unsafe_fn)]
/// # Safety:
/// - the returned `Column` is only used in ways that the `world` has permission for.
/// - the returned `Column` is only used in ways that would not conflict with any existing
/// borrows of world data.
unsafe fn fetch_table(
world: UnsafeWorldCell<'_>,
location: EntityLocation,
component_id: ComponentId,
) -> Option<(&Column, TableRow)> {
let archetype = &world.archetypes()[location.archetype_id];
let table = &world.unsafe_world().storages.tables[archetype.table_id()];
// SAFETY: caller ensures returned data is not misused and we have not created any borrows
// of component/resource data
let table = &unsafe { world.unsafe_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]
#[allow(unsafe_op_in_unsafe_fn)]
/// # Safety:
/// - the returned `ComponentSparseSet` is only used in ways that the `world` has permission for.
/// - the returned `ComponentSparseSet` is only used in ways that would not conflict with any existing
/// borrows of world data.
unsafe fn fetch_sparse_set(
world: UnsafeWorldCell<'_>,
component_id: ComponentId,
) -> Option<&ComponentSparseSet> {
world.unsafe_world().storages.sparse_sets.get(component_id)
// SAFETY: caller ensures returned data is not misused and we have not created any borrows
// of component/resource data
unsafe { world.unsafe_world() }
.storages
.sparse_sets
.get(component_id)
}

0 comments on commit 3a84c74

Please sign in to comment.