mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
optimize cost_for_breaking_block by making its cache an UnsafeCell instead
This commit is contained in:
parent
a599b5614e
commit
d67aa07c13
1 changed files with 3 additions and 2 deletions
|
@ -27,7 +27,7 @@ pub struct CachedWorld {
|
||||||
|
|
||||||
cached_blocks: UnsafeCell<CachedSections>,
|
cached_blocks: UnsafeCell<CachedSections>,
|
||||||
|
|
||||||
cached_mining_costs: RefCell<FxHashMap<BlockPos, f32>>,
|
cached_mining_costs: UnsafeCell<FxHashMap<BlockPos, f32>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -241,7 +241,8 @@ impl CachedWorld {
|
||||||
/// Returns how much it costs to break this block. Returns 0 if the block is
|
/// Returns how much it costs to break this block. Returns 0 if the block is
|
||||||
/// already passable.
|
/// already passable.
|
||||||
pub fn cost_for_breaking_block(&self, pos: BlockPos, mining_cache: &MiningCache) -> f32 {
|
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) {
|
if let Some(&cost) = cached_mining_costs.get(&pos) {
|
||||||
return cost;
|
return cost;
|
||||||
|
|
Loading…
Add table
Reference in a new issue