Skip to content

Commit

Permalink
optimize cost_for_breaking_block by making its cache an UnsafeCell in…
Browse files Browse the repository at this point in the history
…stead
  • Loading branch information
mat-1 committed Dec 24, 2024
1 parent a599b56 commit d67aa07
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions azalea/src/pathfinder/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct CachedWorld {

cached_blocks: UnsafeCell<CachedSections>,

cached_mining_costs: RefCell<FxHashMap<BlockPos, f32>>,
cached_mining_costs: UnsafeCell<FxHashMap<BlockPos, f32>>,
}

#[derive(Default)]
Expand Down Expand Up @@ -241,7 +241,8 @@ impl CachedWorld {
/// Returns how much it costs to break this block. Returns 0 if the block is
/// already passable.
pub fn cost_for_breaking_block(&self, pos: BlockPos, mining_cache: &MiningCache) -> f32 {
let mut cached_mining_costs = self.cached_mining_costs.borrow_mut();
// SAFETY: pathfinding is single-threaded
let cached_mining_costs = unsafe { &mut *self.cached_mining_costs.get() };

if let Some(&cost) = cached_mining_costs.get(&pos) {
return cost;
Expand Down

0 comments on commit d67aa07

Please sign in to comment.