Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,4 @@ impl Display for Error {
f.write_str("bitcode error")
}
}
#[cfg(feature = "std")]
// TODO expose to no_std when error_in_core stabilized (https://github.com/rust-lang/rust/issues/103765)
impl std::error::Error for Error {}
impl core::error::Error for Error {}
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ mod fast;
mod histogram;
mod int;
mod length;
mod nightly;
mod pack;
mod pack_ints;
mod pack_shared;
Expand Down
18 changes: 0 additions & 18 deletions src/nightly.rs

This file was deleted.

28 changes: 16 additions & 12 deletions src/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl PackingTrait for Packing {
impl Packing {
fn read(input: &mut &[u8]) -> Result<(Self, bool)> {
let v = consume_byte(input)?;
let p_u8 = crate::nightly::div_ceil_u8(v, 2);
let p_u8 = v.div_ceil(2);
let offset_by_min = v & 1 != 0;
let p = match p_u8 {
0 => Self::_256,
Expand Down Expand Up @@ -280,7 +280,7 @@ pub fn unpack_bytes_less_than<'a, const N: usize, const HISTOGRAM: usize>(
check_less_than_u8::<N, HISTOGRAM, FACTOR>(out)
} else {
let floor = length / divisor;
let ceil = crate::nightly::div_ceil_usize(length, divisor);
let ceil = length.div_ceil(divisor);
let whole = &original_input[..floor];

// Can only `partial_with_garbage % FACTOR` partial_length times as the rest are undefined garbage.
Expand Down Expand Up @@ -335,6 +335,7 @@ pub fn unpack_bytes_less_than<'a, const N: usize, const HISTOGRAM: usize>(
})
};
if let Ok(h) = histogram {
debug_assert!(check_less_than_u8::<N, 0, FACTOR>(out).is_ok());
debug_assert_eq!(
h,
check_histogram(crate::histogram::histogram(out)).unwrap()
Expand Down Expand Up @@ -439,7 +440,7 @@ fn unpack_arithmetic<const FACTOR: usize>(

// TODO STRICT: check that packed.all(|&b| b < FACTOR.powi(divisor)).
let floor = unpacked_len / divisor;
let ceil = crate::nightly::div_ceil_usize(unpacked_len, divisor);
let ceil = unpacked_len.div_ceil(divisor);
let packed = consume_bytes(input, ceil)?;

debug_assert!(out.is_empty());
Expand Down Expand Up @@ -666,15 +667,18 @@ mod tests {
bench_n!(bench_unpack_arithmetic, 2, 3, 4, 6, 16);

fn test_pack_bytes_less_than_n<const N: usize, const FACTOR: usize>() {
for n in [1, 11, 97, 991, 10007].into_iter().flat_map(|n_prime| {
let divisor = if FACTOR == 256 {
1
} else {
super::factor_to_divisor::<FACTOR>()
};
let n_factor = crate::nightly::div_ceil_usize(n_prime, divisor) * divisor;
[n_factor, n_prime]
}) {
for n in [1usize, 11, 97, 991, 10007]
.into_iter()
.flat_map(|n_prime| {
let divisor = if FACTOR == 256 {
1
} else {
super::factor_to_divisor::<FACTOR>()
};
let n_factor = n_prime.div_ceil(divisor) * divisor;
[n_factor, n_prime]
})
{
let bytes: Vec<_> = crate::random_data(n)
.into_iter()
.map(|v: usize| (v % N as usize) as u8)
Expand Down
2 changes: 1 addition & 1 deletion src/pack_ints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl PackingTrait for Packing {
impl Packing {
fn read<T: SizedUInt>(input: &mut &[u8]) -> Result<(Self, bool)> {
let v = consume_byte(input)?;
let p_u8 = crate::nightly::div_ceil_u8(v, 2) + Self::new(T::MAX) as u8;
let p_u8 = v.div_ceil(2) + Self::new(T::MAX) as u8;
let offset_by_min = v & 1 != 0;
let p = match p_u8 {
0 => Self::_128,
Expand Down
3 changes: 0 additions & 3 deletions src/serde/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ fn get_mut_or_resize<T: Default>(vec: &mut Vec<T>, index: usize) -> &mut T {
unsafe { vec.get_unchecked_mut(index) }
}

#[cfg(not(feature = "std"))]
impl serde::ser::StdError for Error {}

impl serde::ser::Error for Error {
fn custom<T>(t: T) -> Self
where
Expand Down
Loading