| 1 | type Utf8ErrorCompatrust-analyzer cargo simdutf8 0.1.5 implementation/helpers/Utf8ErrorCompat# = craterust-analyzer cargo simdutf8 0.1.5 crate/::compatrust-analyzer cargo simdutf8 0.1.5 compat/::Utf8Errorrust-analyzer cargo simdutf8 0.1.5 compat/Utf8Error#; |
| 2 | |
| 3 | #[inline] |
| 4 | pub(craterust-analyzer cargo simdutf8 0.1.5 crate/) fn validate_utf8_at_offsetrust-analyzer cargo simdutf8 0.1.5 implementation/helpers/validate_utf8_at_offset().(input: &[u8], offset: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Utf8ErrorCompatrust-analyzer cargo simdutf8 0.1.5 implementation/helpers/Utf8ErrorCompat#> { |
| 5 | #[allow(clippy::cast_possible_truncation)] |
| 6 | match corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&input[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().offset..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) { |
| 7 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()), |
| 8 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Utf8ErrorCompatrust-analyzer cargo simdutf8 0.1.5 implementation/helpers/Utf8ErrorCompat# { |
| 9 | valid_up_torust-analyzer cargo simdutf8 0.1.5 compat/Utf8Error#valid_up_to.: err.valid_up_torust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/error/impl#[Utf8Error]valid_up_to().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().offset, |
| 10 | error_lenrust-analyzer cargo simdutf8 0.1.5 compat/Utf8Error#error_len.: err.error_lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/error/impl#[Utf8Error]error_len().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|len| { |
| 11 | // never truncates since std::str::err::Utf8Error::error_len() never returns value larger than 4 |
| 12 | len as u8 |
| 13 | }), |
| 14 | }), |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | #[cold] |
| 19 | #[allow(dead_code)] |
| 20 | #[allow(clippy::unwrap_used)] |
| 21 | pub(craterust-analyzer cargo simdutf8 0.1.5 crate/) fn get_compat_errorrust-analyzer cargo simdutf8 0.1.5 implementation/helpers/get_compat_error().(input: &[u8], failing_block_pos: usize) -> Utf8ErrorCompatrust-analyzer cargo simdutf8 0.1.5 implementation/helpers/Utf8ErrorCompat# { |
| 22 | let offset = if failing_block_pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 23 | // Error must be in this block since it is the first. |
| 24 | 0 |
| 25 | } else { |
| 26 | // The previous block is OK except for a possible continuation over the block boundary. |
| 27 | // We go backwards over the last three bytes of the previous block and find the |
| 28 | // last non-continuation byte as a starting point for an std validation. If the last |
| 29 | // three bytes are all continuation bytes then the previous block ends with a four byte |
| 30 | // UTF-8 codepoint, is thus complete and valid UTF-8. We start the check with the |
| 31 | // current block in that case. |
| 32 | (1..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#3) |
| 33 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|i| input[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().failing_block_pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<&usize>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<&usize>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<&usize>`]sub().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shr<i32>`]shr().6 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0b10) |
| 34 | .map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(failing_block_pos, |i| failing_block_pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().i) |
| 35 | }; |
| 36 | // UNWRAP: safe because the SIMD UTF-8 validation found an error |
| 37 | validate_utf8_at_offsetrust-analyzer cargo simdutf8 0.1.5 implementation/helpers/validate_utf8_at_offset().(input, offset).unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().() |
| 38 | } |
| 39 | |
| 40 | #[allow(dead_code)] |
| 41 | pub(craterust-analyzer cargo simdutf8 0.1.5 crate/) unsafe fn memcpy_unaligned_nonoverlapping_inline_opt_lt_64rust-analyzer cargo simdutf8 0.1.5 implementation/helpers/memcpy_unaligned_nonoverlapping_inline_opt_lt_64().( |
| 42 | mut src: *const u8, |
| 43 | mut dest: *mut u8, |
| 44 | mut len: usize, |
| 45 | ) { |
| 46 | // This gets properly auto-vectorized on AVX 2 and SSE 4.2 |
| 47 | #[inline] |
| 48 | unsafe fn memcpy_u64rust-analyzer cargo simdutf8 0.1.5 implementation/helpers/memcpy_u64().(src: &mut *const u8, dest: &mut *mut u8) { |
| 49 | #[allow(clippy::cast_ptr_alignment)] |
| 50 | dest.castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]cast().::<u64>() |
| 51 | .write_unalignedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]write_unaligned().(src.castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]cast().::<u64>().read_unalignedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]read_unaligned().()); |
| 52 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().src = src.offsetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]offset().(8); |
| 53 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().dest = dest.offsetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]offset().(8); |
| 54 | } |
| 55 | if len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().32 { |
| 56 | memcpy_u64rust-analyzer cargo simdutf8 0.1.5 implementation/helpers/memcpy_u64().(&mut src, &mut dest); |
| 57 | memcpy_u64rust-analyzer cargo simdutf8 0.1.5 implementation/helpers/memcpy_u64().(&mut src, &mut dest); |
| 58 | memcpy_u64rust-analyzer cargo simdutf8 0.1.5 implementation/helpers/memcpy_u64().(&mut src, &mut dest); |
| 59 | memcpy_u64rust-analyzer cargo simdutf8 0.1.5 implementation/helpers/memcpy_u64().(&mut src, &mut dest); |
| 60 | len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().32; |
| 61 | } |
| 62 | if len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().16 { |
| 63 | memcpy_u64rust-analyzer cargo simdutf8 0.1.5 implementation/helpers/memcpy_u64().(&mut src, &mut dest); |
| 64 | memcpy_u64rust-analyzer cargo simdutf8 0.1.5 implementation/helpers/memcpy_u64().(&mut src, &mut dest); |
| 65 | len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().16; |
| 66 | } |
| 67 | if len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().8 { |
| 68 | memcpy_u64rust-analyzer cargo simdutf8 0.1.5 implementation/helpers/memcpy_u64().(&mut src, &mut dest); |
| 69 | len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().8; |
| 70 | } |
| 71 | while len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 72 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().dest = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().src; |
| 73 | src = src.offsetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]offset().(1); |
| 74 | dest = dest.offsetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]offset().(1); |
| 75 | len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | pub(craterust-analyzer cargo simdutf8 0.1.5 crate/) const SIMD_CHUNK_SIZErust-analyzer cargo simdutf8 0.1.5 implementation/helpers/SIMD_CHUNK_SIZE.: usize = 64; |
| 80 | |
| 81 | #[repr(C, align(32))] |
| 82 | #[allow(dead_code)] |
| 83 | pub(craterust-analyzer cargo simdutf8 0.1.5 crate/) struct Utf8CheckAlgorithmrust-analyzer cargo simdutf8 0.1.5 implementation/helpers/Utf8CheckAlgorithm#<T> { |
| 84 | pub(craterust-analyzer cargo simdutf8 0.1.5 crate/) prevrust-analyzer cargo simdutf8 0.1.5 implementation/helpers/Utf8CheckAlgorithm#prev.: T, |
| 85 | pub(craterust-analyzer cargo simdutf8 0.1.5 crate/) incompleterust-analyzer cargo simdutf8 0.1.5 implementation/helpers/Utf8CheckAlgorithm#incomplete.: T, |
| 86 | pub(craterust-analyzer cargo simdutf8 0.1.5 crate/) errorrust-analyzer cargo simdutf8 0.1.5 implementation/helpers/Utf8CheckAlgorithm#error.: T, |
| 87 | } |
| 88 | |
| 89 | #[repr(C, align(16))] |
| 90 | #[allow(dead_code)] |
| 91 | pub(craterust-analyzer cargo simdutf8 0.1.5 crate/) struct TempSimdChunkA16rust-analyzer cargo simdutf8 0.1.5 implementation/helpers/TempSimdChunkA16#(pub(craterust-analyzer cargo simdutf8 0.1.5 crate/) [u8; SIMD_CHUNK_SIZErust-analyzer cargo simdutf8 0.1.5 implementation/helpers/SIMD_CHUNK_SIZE.]); |
| 92 | |
| 93 | #[allow(dead_code)] |
| 94 | impl TempSimdChunkA16rust-analyzer cargo simdutf8 0.1.5 implementation/helpers/TempSimdChunkA16# { |
| 95 | #[inline] |
| 96 | pub(craterust-analyzer cargo simdutf8 0.1.5 crate/) const fn newrust-analyzer cargo simdutf8 0.1.5 implementation/helpers/impl#[TempSimdChunkA16]new().() -> Selfrust-analyzer cargo simdutf8 0.1.5 implementation/helpers/impl#[TempSimdChunkA16] { |
| 97 | Selfrust-analyzer cargo simdutf8 0.1.5 implementation/helpers/impl#[TempSimdChunkA16]([0; SIMD_CHUNK_SIZErust-analyzer cargo simdutf8 0.1.5 implementation/helpers/SIMD_CHUNK_SIZE.]) |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | #[repr(C, align(32))] |
| 102 | #[allow(dead_code)] |
| 103 | pub(craterust-analyzer cargo simdutf8 0.1.5 crate/) struct TempSimdChunkA32rust-analyzer cargo simdutf8 0.1.5 implementation/helpers/TempSimdChunkA32#(pub(craterust-analyzer cargo simdutf8 0.1.5 crate/) [u8; SIMD_CHUNK_SIZErust-analyzer cargo simdutf8 0.1.5 implementation/helpers/SIMD_CHUNK_SIZE.]); |
| 104 | |
| 105 | #[allow(dead_code)] |
| 106 | impl TempSimdChunkA32rust-analyzer cargo simdutf8 0.1.5 implementation/helpers/TempSimdChunkA32# { |
| 107 | #[inline] |
| 108 | pub(craterust-analyzer cargo simdutf8 0.1.5 crate/) const fn newrust-analyzer cargo simdutf8 0.1.5 implementation/helpers/impl#[TempSimdChunkA32]new().() -> Selfrust-analyzer cargo simdutf8 0.1.5 implementation/helpers/impl#[TempSimdChunkA32] { |
| 109 | Selfrust-analyzer cargo simdutf8 0.1.5 implementation/helpers/impl#[TempSimdChunkA32]([0; SIMD_CHUNK_SIZErust-analyzer cargo simdutf8 0.1.5 implementation/helpers/SIMD_CHUNK_SIZE.]) |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)] |
| 114 | #[allow(dead_code)] |
| 115 | pub(craterust-analyzer cargo simdutf8 0.1.5 crate/) struct SimdU8Valuerust-analyzer cargo simdutf8 0.1.5 implementation/helpers/SimdU8Value#<T>(pub(craterust-analyzer cargo simdutf8 0.1.5 crate/) T) |
| 116 | where |
| 117 | T: Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy#; |