diff --git a/src/arch/wasm32.rs b/src/arch/wasm32.rs index e800f45..381ea96 100644 --- a/src/arch/wasm32.rs +++ b/src/arch/wasm32.rs @@ -4,7 +4,7 @@ use super::generic; use crate::get_chars_table; use core::arch::wasm32::*; -pub(crate) const USE_CHECK_FN: bool = false; +pub(crate) const USE_CHECK_FN: bool = true; #[inline(always)] fn has_simd128() -> bool { diff --git a/src/lib.rs b/src/lib.rs index e3918f7..ee712f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -609,6 +609,8 @@ fn decode_to_slice_inner(input: &[u8], output: &mut [u8]) -> Result<(), FromHexE /// Assumes `output.len() == input.len() / 2`. #[inline] unsafe fn decode_checked(input: &[u8], output: &mut [u8]) -> Result<(), FromHexError> { + debug_assert_eq!(output.len(), input.len() / 2); + if imp::USE_CHECK_FN { // check then decode if imp::check(input) { @@ -628,7 +630,7 @@ unsafe fn decode_checked(input: &[u8], output: &mut [u8]) -> Result<(), FromHexE #[inline] const fn byte2hex(byte: u8) -> (u8, u8) { let table = get_chars_table::(); - let high = table[((byte & 0xf0) >> 4) as usize]; + let high = table[(byte >> 4) as usize]; let low = table[(byte & 0x0f) as usize]; (high, low) }