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

remove unchecked_utf8 and read_in_unchecked

This commit is contained in:
Robin Appelman 2019-07-24 12:16:40 +02:00
commit 613199c089
2 changed files with 3 additions and 14 deletions

View file

@ -17,7 +17,4 @@ bitstream_reader_derive = { version = "0.5", path = "bitstream_reader_derive" }
[dev-dependencies] [dev-dependencies]
maplit = "1.0.1" maplit = "1.0.1"
[features]
unchecked_utf8 = []
[workspace] [workspace]

View file

@ -255,7 +255,7 @@ where
/// [`ReadError::NotEnoughData`]: enum.ReadError.html#variant.NotEnoughData /// [`ReadError::NotEnoughData`]: enum.ReadError.html#variant.NotEnoughData
/// [`ReadError::TooManyBits`]: enum.ReadError.html#variant.TooManyBits /// [`ReadError::TooManyBits`]: enum.ReadError.html#variant.TooManyBits
#[inline] #[inline]
pub fn read_int_unchecked<T>(&self, position: usize, count: usize) -> T fn read_int_unchecked<T>(&self, position: usize, count: usize) -> T
where where
T: PrimInt + BitOrAssign + IsSigned + UncheckedPrimitiveInt, T: PrimInt + BitOrAssign + IsSigned + UncheckedPrimitiveInt,
{ {
@ -463,23 +463,15 @@ where
match byte_len { match byte_len {
Some(byte_len) => { Some(byte_len) => {
let bytes = self.read_bytes(position, byte_len)?; let bytes = self.read_bytes(position, byte_len)?;
let raw_string = if cfg!(feature = "unchecked_utf8") { let raw_string = String::from_utf8(bytes)?;
unsafe { String::from_utf8_unchecked(bytes) }
} else {
String::from_utf8(bytes)?
};
Ok(raw_string.trim_end_matches(char::from(0)).to_owned()) Ok(raw_string.trim_end_matches(char::from(0)).to_owned())
} }
None => { None => {
let bytes = self.read_string_bytes(position); let bytes = self.read_string_bytes(position);
if cfg!(feature = "unchecked_utf8") {
unsafe { Ok(String::from_utf8_unchecked(bytes)) }
} else {
String::from_utf8(bytes).map_err(ReadError::from) String::from_utf8(bytes).map_err(ReadError::from)
} }
} }
} }
}
fn read_string_bytes(&self, position: usize) -> Vec<u8> { fn read_string_bytes(&self, position: usize) -> Vec<u8> {
let mut acc = Vec::with_capacity(32); let mut acc = Vec::with_capacity(32);