More ergonomic interface, clear defaults
This commit is contained in:
parent
9a878ff83d
commit
9daecc56ea
26
src/dec.rs
26
src/dec.rs
|
@ -297,7 +297,7 @@ fn decode_hex_bytes_unchecked(ascii: &[u8], bytes: &mut [MaybeUninit<u8>]) -> bo
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const VECTORED: bool = true;
|
const VECTORED: bool = false;
|
||||||
if VECTORED {
|
if VECTORED {
|
||||||
unsafe { arch::_mm_prefetch(ASCII_DIGITS_SIMD as *const i8, arch::_MM_HINT_T0) };
|
unsafe { arch::_mm_prefetch(ASCII_DIGITS_SIMD as *const i8, arch::_MM_HINT_T0) };
|
||||||
let mut bad: arch::__m256i = u8::splat_zero().into();
|
let mut bad: arch::__m256i = u8::splat_zero().into();
|
||||||
|
@ -438,6 +438,30 @@ pub fn hex_bytes_dyn(ascii: &[u8]) -> Option<Box<[u8]>> {
|
||||||
.map(|v| v.into_boxed_slice())
|
.map(|v| v.into_boxed_slice())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Decoder;
|
||||||
|
|
||||||
|
impl Decoder {
|
||||||
|
#[inline]
|
||||||
|
pub fn decode_sized<const N: usize>(ascii: &[u8; N * 2]) -> Option<[u8; N]> {
|
||||||
|
// benchmarks show this to be fastest
|
||||||
|
hex_bytes_sized_const(ascii)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
|
#[inline]
|
||||||
|
pub fn decode_sized_heap<const N: usize>(ascii: &[u8; N * 2]) -> Option<Box<[u8; N]>> {
|
||||||
|
// benchmarks show this to be fastest
|
||||||
|
hex_bytes_sized_heap(ascii)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
|
#[inline]
|
||||||
|
pub fn decode(ascii: &[u8]) -> Option<Box<[u8]>> {
|
||||||
|
// benchmarks show this to be fastest
|
||||||
|
hex_bytes_dyn_unsafe_iter(ascii)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
#![feature(const_trait_impl)]
|
#![feature(const_trait_impl)]
|
||||||
#![feature(extend_one)]
|
#![feature(extend_one)]
|
||||||
#![feature(generic_const_exprs)]
|
#![feature(generic_const_exprs)]
|
||||||
#![feature(int_log)]
|
|
||||||
#![feature(maybe_uninit_slice)]
|
#![feature(maybe_uninit_slice)]
|
||||||
#![feature(maybe_uninit_uninit_array)]
|
#![feature(maybe_uninit_uninit_array)]
|
||||||
#![feature(maybe_uninit_array_assume_init)]
|
#![feature(maybe_uninit_array_assume_init)]
|
||||||
|
@ -31,3 +30,6 @@ pub mod dec;
|
||||||
pub mod enc;
|
pub mod enc;
|
||||||
|
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
|
|
||||||
|
pub use dec::Decoder;
|
||||||
|
pub use enc::{Encode, Encoder};
|
||||||
|
|
|
@ -6,4 +6,5 @@ pub(crate) use brisk::util;
|
||||||
|
|
||||||
pub(crate) use crate::defs::*;
|
pub(crate) use crate::defs::*;
|
||||||
|
|
||||||
|
pub use crate::dec::Decoder as HexDecoder;
|
||||||
pub use crate::enc::{Encode as _, Encoder as HexEncoder};
|
pub use crate::enc::{Encode as _, Encoder as HexEncoder};
|
||||||
|
|
Loading…
Reference in New Issue