Skip to content

Commit 65ecac9

Browse files
committed
Obey clippy
Signed-off-by: Heinz N. Gies <heinz@licenser.net>
1 parent 938ae9b commit 65ecac9

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

src/neon/deser.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
use crate::error::ErrorType;
22
use crate::neon::stage1::bit_mask;
3-
use crate::stringparse::*;
3+
use crate::stringparse::{handle_unicode_codepoint, ESCAPE_MAP};
44
use crate::Deserializer;
55
use crate::Result;
6-
use std::arch::aarch64::*;
6+
use std::arch::aarch64::{
7+
uint8x16_t, vandq_u8, vceqq_u8, vgetq_lane_u32, vld1q_u8, vmovq_n_u8, vpaddq_u8,
8+
vreinterpretq_u32_u8,
9+
};
710

811
#[cfg_attr(not(feature = "no-inline"), inline(always))]
912
fn find_bs_bits_and_quote_bits(v0: uint8x16_t, v1: uint8x16_t) -> (u32, u32) {
@@ -51,7 +54,7 @@ impl<'de> Deserializer<'de> {
5154
buffer: &'invoke mut [u8],
5255
mut idx: usize,
5356
) -> Result<&'de str> {
54-
use ErrorType::*;
57+
use ErrorType::{InvalidEscape, InvalidUnicodeCodepoint};
5558
let input: &mut [u8] = unsafe { std::mem::transmute(input) };
5659
// Add 1 to skip the initial "
5760
idx += 1;

src/neon/stage1.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
use crate::*;
2-
use std::arch::aarch64::*;
1+
use crate::{static_cast_i32, Stage1Parse};
2+
use std::arch::aarch64::{
3+
int32x4_t, int8x16_t, uint8x16_t, vaddq_s32, vandq_u8, vceqq_u8, vcleq_u8, vdupq_n_s8,
4+
vgetq_lane_u64, vld1q_u8, vmovq_n_u8, vmull_p64, vpaddq_u8, vqtbl1q_u8, vreinterpretq_u64_u8,
5+
vreinterpretq_u8_s8, vshrq_n_u8, vtstq_u8,
6+
};
37
use std::mem;
48

59
// NEON-SPECIFIC
@@ -51,10 +55,10 @@ impl SimdInput {
5155
pub(crate) fn new(ptr: &[u8]) -> Self {
5256
unsafe {
5357
Self {
54-
v0: vld1q_u8(ptr.as_ptr() as *const u8),
55-
v1: vld1q_u8(ptr.as_ptr().add(16) as *const u8),
56-
v2: vld1q_u8(ptr.as_ptr().add(32) as *const u8),
57-
v3: vld1q_u8(ptr.as_ptr().add(48) as *const u8),
58+
v0: vld1q_u8(ptr.as_ptr().cast::<u8>()),
59+
v1: vld1q_u8(ptr.as_ptr().add(16).cast::<u8>()),
60+
v2: vld1q_u8(ptr.as_ptr().add(32).cast::<u8>()),
61+
v3: vld1q_u8(ptr.as_ptr().add(48).cast::<u8>()),
5862
}
5963
}
6064
}
@@ -66,8 +70,8 @@ impl Stage1Parse<int8x16_t> for SimdInput {
6670
unsafe {
6771
vgetq_lane_u64(
6872
vreinterpretq_u64_u8(mem::transmute(vmull_p64(
69-
mem::transmute(-1 as i64),
70-
mem::transmute(quote_bits as i64),
73+
mem::transmute(-1_i64),
74+
mem::transmute(quote_bits),
7175
))),
7276
0,
7377
)
@@ -178,7 +182,11 @@ impl Stage1Parse<int8x16_t> for SimdInput {
178182
// needs to be large enough to handle this
179183
//TODO: usize was u32 here does this matter?
180184
#[cfg_attr(not(feature = "no-inline"), inline(always))]
181-
#[allow(clippy::cast_possible_wrap, clippy::cast_ptr_alignment)]
185+
#[allow(
186+
clippy::cast_possible_wrap,
187+
clippy::cast_ptr_alignment,
188+
clippy::uninit_vec
189+
)]
182190
fn flatten_bits(base: &mut Vec<u32>, idx: u32, mut bits: u64) {
183191
let cnt: usize = bits.count_ones() as usize;
184192
let mut l = base.len();
@@ -215,7 +223,7 @@ impl Stage1Parse<int8x16_t> for SimdInput {
215223

216224
let v: int32x4_t = mem::transmute([v0, v1, v2, v3]);
217225
let v: int32x4_t = vaddq_s32(idx_64_v, v);
218-
std::ptr::write(base.as_mut_ptr().add(l) as *mut int32x4_t, v);
226+
std::ptr::write(base.as_mut_ptr().add(l).cast::<int32x4_t>(), v);
219227
}
220228
l += 4;
221229
}

src/numberparse.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,14 @@ fn parse_eight_digits_unrolled(chars: &[u8]) -> u32 {
161161

162162
#[cfg_attr(not(feature = "no-inline"), inline)]
163163
#[cfg(any(target_feature = "neon", target_feature = "simd128"))]
164+
#[allow(clippy::cast_ptr_alignment)]
164165
fn parse_eight_digits_unrolled(chars: &[u8]) -> u32 {
165-
let val: u64 = unsafe { *(chars.as_ptr() as *const u64) };
166+
let val: u64 = unsafe { *(chars.as_ptr().cast::<u64>()) };
166167
// memcpy(&val, chars, sizeof(u64));
167-
let val = (val & 0x0F0F0F0F0F0F0F0F).wrapping_mul(2561) >> 8;
168-
let val = (val & 0x00FF00FF00FF00FF).wrapping_mul(6553601) >> 16;
168+
let val = (val & 0x0F0F_0F0F_0F0F_0F0F).wrapping_mul(2561) >> 8;
169+
let val = (val & 0x00FF_00FF_00FF_00FF).wrapping_mul(6_553_601) >> 16;
169170

170-
return ((val & 0x0000FFFF0000FFFF).wrapping_mul(42949672960001) >> 32) as u32;
171+
((val & 0x0000_FFFF_0000_FFFF).wrapping_mul(42_949_672_960_001) >> 32) as u32
171172
}
172173

173174
impl<'de> Deserializer<'de> {

0 commit comments

Comments
 (0)