From d67aa07c13c335b135080efc59f82df69aa34a95 Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 24 Dec 2024 12:41:11 +0000 Subject: [PATCH] optimize cost_for_breaking_block by making its cache an UnsafeCell instead --- azalea/src/pathfinder/world.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/azalea/src/pathfinder/world.rs b/azalea/src/pathfinder/world.rs index 924ee33a..255f99d3 100644 --- a/azalea/src/pathfinder/world.rs +++ b/azalea/src/pathfinder/world.rs @@ -27,7 +27,7 @@ pub struct CachedWorld { cached_blocks: UnsafeCell, - cached_mining_costs: RefCell>, + cached_mining_costs: UnsafeCell>, } #[derive(Default)] @@ -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;