Skip to content

Commit 6141a65

Browse files
committed
Minor BitCounter optimization
1 parent 0626232 commit 6141a65

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/write.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,19 @@ impl<N: Counter> BitWrite for BitCounter<N> {
19041904
Ok(())
19051905
}
19061906

1907+
#[inline]
1908+
fn write_const<const BITS: u32, const VALUE: u32>(&mut self) -> io::Result<()> {
1909+
const {
1910+
assert!(
1911+
BITS == 0 || VALUE <= (u32::ALL >> (u32::BITS_SIZE - BITS)),
1912+
"excessive value for bits written"
1913+
);
1914+
}
1915+
1916+
self.bits.checked_add_assign(BITS.try_into().map_err(|_| Overflowed)?)?;
1917+
Ok(())
1918+
}
1919+
19071920
#[inline]
19081921
fn write_unsigned<const BITS: u32, U>(&mut self, value: U) -> io::Result<()>
19091922
where

0 commit comments

Comments
 (0)