From 9686a0041911f5a6724c5933de57214bd940baac Mon Sep 17 00:00:00 2001 From: Nugine Date: Wed, 18 Jan 2023 22:35:24 +0800 Subject: chore: upgrade base64-simd to 0.8.0 (#17463) This PR upgrades the `base64-simd` dependency of `deno_web`. base64-simd v0.8 supports `forgiving_decode` in ["copy" mode](https://docs.rs/base64-simd/0.8.0/base64_simd/fn.forgiving_decode.html), ["inplace" mode](https://docs.rs/base64-simd/0.8.0/base64_simd/fn.forgiving_decode_inplace.html) or ["alloc" mode](https://docs.rs/base64-simd/0.8.0/base64_simd/fn.forgiving_decode_to_vec.html). When #17159 resolves, they can be used to reduce unnecessary allocations and copies. base64-simd v0.8 also supports AArch64 SIMD out of box. --- ext/web/lib.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'ext/web/lib.rs') diff --git a/ext/web/lib.rs b/ext/web/lib.rs index de8984232..92cfcceeb 100644 --- a/ext/web/lib.rs +++ b/ext/web/lib.rs @@ -130,25 +130,27 @@ pub fn init( #[op] fn op_base64_decode(input: String) -> Result { let mut s = input.into_bytes(); - let decoded_len = forgiving_base64_decode(&mut s)?; + let decoded_len = forgiving_base64_decode_inplace(&mut s)?; s.truncate(decoded_len); Ok(s.into()) } #[op] fn op_base64_atob(mut s: ByteString) -> Result { - let decoded_len = forgiving_base64_decode(&mut s)?; + let decoded_len = forgiving_base64_decode_inplace(&mut s)?; s.truncate(decoded_len); Ok(s) } /// See #[inline] -fn forgiving_base64_decode(input: &mut [u8]) -> Result { +fn forgiving_base64_decode_inplace( + input: &mut [u8], +) -> Result { let error: _ = || DomExceptionInvalidCharacterError::new("Failed to decode base64"); - let decoded = base64_simd::Base64::forgiving_decode_inplace(input) - .map_err(|_| error())?; + let decoded = + base64_simd::forgiving_decode_inplace(input).map_err(|_| error())?; Ok(decoded.len()) } @@ -165,8 +167,7 @@ fn op_base64_btoa(s: ByteString) -> String { /// See #[inline] fn forgiving_base64_encode(s: &[u8]) -> String { - const BASE64_STANDARD: base64_simd::Base64 = base64_simd::Base64::STANDARD; - BASE64_STANDARD.encode_to_boxed_str(s).into_string() + base64_simd::STANDARD.encode_to_string(s) } #[op] -- cgit v1.2.3