diff options
| author | mat <git@matdoes.dev> | 2026-01-04 22:41:27 +1100 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2026-01-04 22:41:27 +1100 |
| commit | 23e982f8f28e5fb816e803e66b3a3ed1aa6d0506 (patch) | |
| tree | 35a0ffabfb4cf2347c24e16fdb2364566aeddcaf /azalea | |
| parent | 203d178dab15206a6c19b7e8063f9f397373b118 (diff) | |
| download | azalea-drasl-23e982f8f28e5fb816e803e66b3a3ed1aa6d0506.tar.xz | |
slightly faster hash impl for pathfinder RelBlockPos
Diffstat (limited to 'azalea')
| -rw-r--r-- | azalea/src/pathfinder/rel_block_pos.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/azalea/src/pathfinder/rel_block_pos.rs b/azalea/src/pathfinder/rel_block_pos.rs index 6b5fa69a..b8e96041 100644 --- a/azalea/src/pathfinder/rel_block_pos.rs +++ b/azalea/src/pathfinder/rel_block_pos.rs @@ -1,4 +1,8 @@ -use std::ops::{Add, Mul}; +use std::{ + hash::{Hash, Hasher}, + mem::transmute, + ops::{Add, Mul}, +}; use azalea_core::position::BlockPos; @@ -7,7 +11,7 @@ use azalea_core::position::BlockPos; /// This fits in 64 bits, so it's more efficient than a BlockPos in some cases. /// /// The X and Z are limited to ±32k. -#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] #[repr(C)] pub struct RelBlockPos { pub x: i16, @@ -89,6 +93,12 @@ impl RelBlockPos { z: self.z, } } + + #[inline] + pub fn as_u64(self) -> u64 { + // SAFETY: RelBlockPos can be represented as a u64 + unsafe { transmute::<Self, u64>(self) } + } } impl Add<RelBlockPos> for RelBlockPos { @@ -113,3 +123,9 @@ impl Mul<i16> for RelBlockPos { } } } + +impl Hash for RelBlockPos { + fn hash<H: Hasher>(&self, state: &mut H) { + self.as_u64().hash(state); + } +} |
