aboutsummaryrefslogtreecommitdiff
path: root/azalea
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2024-12-24 12:41:11 +0000
committermat <git@matdoes.dev>2024-12-24 12:41:18 +0000
commitd67aa07c13c335b135080efc59f82df69aa34a95 (patch)
treea74be447058db8b5cc6237e5d25279f5f701d06a /azalea
parenta599b5614e6acf65e552940fff99a9252a600472 (diff)
downloadazalea-drasl-d67aa07c13c335b135080efc59f82df69aa34a95.tar.xz
optimize cost_for_breaking_block by making its cache an UnsafeCell instead
Diffstat (limited to 'azalea')
-rw-r--r--azalea/src/pathfinder/world.rs5
1 files 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<CachedSections>,
- cached_mining_costs: RefCell<FxHashMap<BlockPos, f32>>,
+ cached_mining_costs: UnsafeCell<FxHashMap<BlockPos, f32>>,
}
#[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;