diff --git a/src/bitboard.rs b/src/bitboard.rs index bbda9d8..ab2bef1 100644 --- a/src/bitboard.rs +++ b/src/bitboard.rs @@ -51,23 +51,9 @@ impl BitBoard { #[cfg(not(feature = "bitvec"))] pub const fn set(&mut self, row: usize, col: usize, value: bool) { let index = Self::get_index(row, col); - if value { - self.set_bit(index); // Set the bit at (row, col) to 1 - } else { - self.clear_bit(index); // Clear the bit at (row, col) - } - } - - #[cfg(not(feature = "bitvec"))] - const fn clear_bit(&mut self, index: usize) { - self.0 &= !(1 << index) - } - - // PERF! was going to optimize setting multiple indexes, - // seems rust does this for us: https://godbolt.org/z/ddj3dMxsP - #[cfg(not(feature = "bitvec"))] - const fn set_bit(&mut self, index: usize) { - self.0 |= 1 << index + // PERF! branchless setting of bit (~+3% perf bump) + self.0 &= !(1 << index); // clear bit + self.0 |= (value as BitBoardInner) << index; // set bit (if needed) } const fn get_index(row: usize, col: usize) -> usize {