Skip to content

Commit bcf57fc

Browse files
committed
clippy
Signed-off-by: Heinz N. Gies <[email protected]>
1 parent ae5558f commit bcf57fc

File tree

1 file changed

+44
-38
lines changed

1 file changed

+44
-38
lines changed

src/generator.rs

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -257,57 +257,63 @@ pub trait BaseGenerator {
257257

258258
#[inline]
259259
unsafe fn bit_mask() -> uint8x16_t {
260-
mem::transmute([
261-
0x01_u8, 0x02, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x01, 0x02, 0x4, 0x8, 0x10, 0x20,
262-
0x40, 0x80,
263-
])
260+
unsafe {
261+
mem::transmute([
262+
0x01_u8, 0x02, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x01, 0x02, 0x4, 0x8, 0x10,
263+
0x20, 0x40, 0x80,
264+
])
265+
}
264266
}
265267

266268
#[inline]
267269
unsafe fn neon_movemask(input: uint8x16_t) -> u16 {
268-
let simd_input: uint8x16_t = vandq_u8(input, bit_mask());
269-
let tmp: uint8x16_t = vpaddq_u8(simd_input, simd_input);
270-
let tmp = vpaddq_u8(tmp, tmp);
271-
let tmp = vpaddq_u8(tmp, tmp);
270+
unsafe {
271+
let simd_input: uint8x16_t = vandq_u8(input, bit_mask());
272+
let tmp: uint8x16_t = vpaddq_u8(simd_input, simd_input);
273+
let tmp = vpaddq_u8(tmp, tmp);
274+
let tmp = vpaddq_u8(tmp, tmp);
272275

273-
vgetq_lane_u16(vreinterpretq_u16_u8(tmp), 0)
276+
vgetq_lane_u16(vreinterpretq_u16_u8(tmp), 0)
277+
}
274278
}
275279

276280
let writer = self.get_writer();
277281
// The case where we have a 16+ byte block
278282
// we repeate the same logic as above but with
279283
// only 16 bytes
280284
let mut idx = 0;
281-
let zero = vdupq_n_u8(0);
282-
let lower_quote_range = vdupq_n_u8(0x1F);
283-
let quote = vdupq_n_u8(b'"');
284-
let backslash = vdupq_n_u8(b'\\');
285-
while string.len() - idx > 16 {
286-
// Load 16 bytes of data;
287-
let data: uint8x16_t = vld1q_u8(string.as_ptr().add(idx));
288-
// Test the data against being backslash and quote.
289-
let bs_or_quote = vorrq_u8(vceqq_u8(data, backslash), vceqq_u8(data, quote));
290-
// Now mask the data with the quote range (0x1F).
291-
let in_quote_range = vandq_u8(data, lower_quote_range);
292-
// then test of the data is unchanged. aka: xor it with the
293-
// Any field that was inside the quote range it will be zero
294-
// now.
295-
let is_unchanged = veorq_u8(data, in_quote_range);
296-
let in_range = vceqq_u8(is_unchanged, zero);
297-
let quote_bits = neon_movemask(vorrq_u8(bs_or_quote, in_range));
298-
if quote_bits == 0 {
299-
idx += 16;
300-
} else {
301-
let quote_dist = quote_bits.trailing_zeros() as usize;
302-
stry!(writer.write_all(&string[0..idx + quote_dist]));
303-
let ch = string[idx + quote_dist];
304-
match ESCAPED[ch as usize] {
305-
b'u' => stry!(u_encode(writer, ch)),
306-
escape => stry!(writer.write_all(&[b'\\', escape])),
285+
unsafe {
286+
let zero = vdupq_n_u8(0);
287+
let lower_quote_range = vdupq_n_u8(0x1F);
288+
let quote = vdupq_n_u8(b'"');
289+
let backslash = vdupq_n_u8(b'\\');
290+
while string.len() - idx > 16 {
291+
// Load 16 bytes of data;
292+
let data: uint8x16_t = vld1q_u8(string.as_ptr().add(idx));
293+
// Test the data against being backslash and quote.
294+
let bs_or_quote = vorrq_u8(vceqq_u8(data, backslash), vceqq_u8(data, quote));
295+
// Now mask the data with the quote range (0x1F).
296+
let in_quote_range = vandq_u8(data, lower_quote_range);
297+
// then test of the data is unchanged. aka: xor it with the
298+
// Any field that was inside the quote range it will be zero
299+
// now.
300+
let is_unchanged = veorq_u8(data, in_quote_range);
301+
let in_range = vceqq_u8(is_unchanged, zero);
302+
let quote_bits = neon_movemask(vorrq_u8(bs_or_quote, in_range));
303+
if quote_bits == 0 {
304+
idx += 16;
305+
} else {
306+
let quote_dist = quote_bits.trailing_zeros() as usize;
307+
stry!(writer.write_all(&string[0..idx + quote_dist]));
308+
let ch = string[idx + quote_dist];
309+
match ESCAPED[ch as usize] {
310+
b'u' => stry!(u_encode(writer, ch)),
311+
escape => stry!(writer.write_all(&[b'\\', escape])),
312+
}
313+
314+
*string = &string[idx + quote_dist + 1..];
315+
idx = 0;
307316
}
308-
309-
*string = &string[idx + quote_dist + 1..];
310-
idx = 0;
311317
}
312318
}
313319
stry!(writer.write_all(&string[0..idx]));

0 commit comments

Comments
 (0)