diff options
| author | mat <git@matdoes.dev> | 2024-12-24 12:41:11 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2024-12-24 12:41:18 +0000 |
| commit | d67aa07c13c335b135080efc59f82df69aa34a95 (patch) | |
| tree | a74be447058db8b5cc6237e5d25279f5f701d06a | |
| parent | a599b5614e6acf65e552940fff99a9252a600472 (diff) | |
| download | azalea-drasl-d67aa07c13c335b135080efc59f82df69aa34a95.tar.xz | |
optimize cost_for_breaking_block by making its cache an UnsafeCell instead
| -rw-r--r-- | azalea/src/pathfinder/world.rs | 5 |
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; |
