From 9844e95e5f1afa920727d0d93a9fd436f600bc21 Mon Sep 17 00:00:00 2001 From: haslersn Date: Thu, 29 Aug 2019 17:55:05 +0200 Subject: [PATCH] common: Stop abusing wild animals for bit shifts --- common/src/volumes/vol_map_2d.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/common/src/volumes/vol_map_2d.rs b/common/src/volumes/vol_map_2d.rs index 86fac2c251..f7458d46a5 100644 --- a/common/src/volumes/vol_map_2d.rs +++ b/common/src/volumes/vol_map_2d.rs @@ -26,19 +26,13 @@ pub struct VolMap2d { impl VolMap2d { #[inline(always)] pub fn chunk_key>>(pos: P) -> Vec2 { - pos.into().map2(S::SIZE.into(), |e, sz: u32| { - // Horrid, but it's faster than a cheetah with a red bull blood transfusion - let log2 = (sz - 1).count_ones(); - ((((i64::from(e) + (1 << 32)) as u64) >> log2) - (1 << (32 - log2))) as i32 - }) + pos.into() + .map2(S::SIZE.into(), |e, sz: u32| e >> (sz - 1).count_ones()) } #[inline(always)] pub fn chunk_offs(pos: Vec3) -> Vec3 { - let offs = pos.map2(S::SIZE, |e, sz| { - // Horrid, but it's even faster than the aforementioned cheetah - (((i64::from(e) + (1 << 32)) as u64) & u64::from(sz - 1)) as i32 - }); + let offs = pos.map2(S::SIZE, |e, sz| e & (sz - 1) as i32); Vec3::new(offs.x, offs.y, pos.z) } }