1
0
Fork 0
mirror of https://codeberg.org/icewind/bitbuffer.git synced 2026-06-03 16:44:06 +02:00

minor read bool improvement

This commit is contained in:
Robin Appelman 2021-07-18 20:04:26 +02:00
commit 5bd8313a51

View file

@ -293,8 +293,7 @@ where
let byte_index = position / 8; let byte_index = position / 8;
let bit_offset = position & 7; let bit_offset = position & 7;
if position < self.bit_len() { if let Some(byte) = self.slice.get(byte_index) {
let byte = self.slice[byte_index];
if E::is_le() { if E::is_le() {
let shifted = byte >> bit_offset as u8; let shifted = byte >> bit_offset as u8;
Ok(shifted & 1u8 == 1) Ok(shifted & 1u8 == 1)
@ -305,7 +304,7 @@ where
} else { } else {
Err(BitError::NotEnoughData { Err(BitError::NotEnoughData {
requested: 1, requested: 1,
bits_left: self.bit_len().saturating_sub(position), bits_left: 0,
}) })
} }
} }