Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename UnsafeWorldCell::read_change_tick #8588

Merged
merged 4 commits into from
May 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions crates/bevy_ecs/src/world/unsafe_world_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
system::Resource,
};
use bevy_ptr::Ptr;
use std::{any::TypeId, cell::UnsafeCell, marker::PhantomData, sync::atomic::Ordering};
use std::{any::TypeId, cell::UnsafeCell, marker::PhantomData};

/// Variant of the [`World`] where resource and component accesses take `&self`, and the responsibility to avoid
/// aliasing violations are given to the caller instead of being checked at compile-time by rust's unique XOR shared rule.
Expand Down Expand Up @@ -191,13 +191,17 @@ impl<'w> UnsafeWorldCell<'w> {

/// Reads the current change tick of this world.
#[inline]
#[deprecated = "this method has been renamed to `UnsafeWorldCell::change_tick`"]
pub fn read_change_tick(self) -> Tick {
self.change_tick()
}

/// Gets the current change tick of this world.
#[inline]
pub fn change_tick(self) -> Tick {
// SAFETY:
// - we only access world metadata
let tick = unsafe { self.world_metadata() }
.change_tick
.load(Ordering::Acquire);
Tick::new(tick)
unsafe { self.world_metadata() }.read_change_tick()
}

#[inline]
Expand Down Expand Up @@ -382,7 +386,7 @@ impl<'w> UnsafeWorldCell<'w> {
// - index is in-bounds because the column is initialized and non-empty
// - the caller promises that no other reference to the ticks of the same row can exist at the same time
let ticks = unsafe {
TicksMut::from_tick_cells(ticks, self.last_change_tick(), self.read_change_tick())
TicksMut::from_tick_cells(ticks, self.last_change_tick(), self.change_tick())
};

Some(MutUntyped {
Expand Down Expand Up @@ -430,7 +434,7 @@ impl<'w> UnsafeWorldCell<'w> {
self,
component_id: ComponentId,
) -> Option<MutUntyped<'w>> {
let change_tick = self.read_change_tick();
let change_tick = self.change_tick();
// SAFETY: we only access data that the caller has ensured is unaliased and `self`
// has permission to access.
let (ptr, ticks) = unsafe { self.unsafe_world() }
Expand Down Expand Up @@ -650,9 +654,7 @@ impl<'w> UnsafeEntityCell<'w> {
#[inline]
pub unsafe fn get_mut<T: Component>(self) -> Option<Mut<'w, T>> {
// SAFETY: same safety requirements
unsafe {
self.get_mut_using_ticks(self.world.last_change_tick(), self.world.read_change_tick())
}
unsafe { self.get_mut_using_ticks(self.world.last_change_tick(), self.world.change_tick()) }
}

/// # Safety
Expand Down Expand Up @@ -744,7 +746,7 @@ impl<'w> UnsafeEntityCell<'w> {
ticks: TicksMut::from_tick_cells(
cells,
self.world.last_change_tick(),
self.world.read_change_tick(),
self.world.change_tick(),
),
})
}
Expand Down