mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 16:44:06 +02:00
miri being difficult on purpose to ensure we dont take shortcuts
This commit is contained in:
parent
ed249331e1
commit
9d04fbe7cf
1 changed files with 5 additions and 15 deletions
|
|
@ -293,23 +293,13 @@ macro_rules! impl_into_bytes {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn into_u16(self) -> Self::U16Iter {
|
fn into_u16(self) -> Self::U16Iter {
|
||||||
use std::convert::TryInto;
|
|
||||||
use std::mem::align_of;
|
|
||||||
|
|
||||||
let bytes = self.to_le_bytes();
|
let bytes = self.to_le_bytes();
|
||||||
if align_of::<Self>() >= align_of::<u16>() {
|
let mut shorts = [0; $shorts];
|
||||||
let (head, aligned, tail) = unsafe { bytes[..].align_to::<u16>() };
|
let mut chunks = bytes.chunks(2).zip(shorts.iter_mut());
|
||||||
debug_assert_eq!(0, head.len());
|
while let Some((&[a, b], short)) = chunks.next() {
|
||||||
debug_assert_eq!(0, tail.len());
|
*short = (b as u16) << 8 | a as u16;
|
||||||
Self::U16Iter::new(aligned.try_into().unwrap())
|
|
||||||
} else {
|
|
||||||
let mut shorts = [0; $shorts];
|
|
||||||
let mut chunks = bytes.chunks(2).zip(shorts.iter_mut());
|
|
||||||
while let Some((&[a, b], short)) = chunks.next() {
|
|
||||||
*short = (b as u16) << 8 | a as u16;
|
|
||||||
}
|
|
||||||
Self::U16Iter::new(shorts)
|
|
||||||
}
|
}
|
||||||
|
Self::U16Iter::new(shorts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue