Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
Signed-off-by: Heinz N. Gies <[email protected]>
  • Loading branch information
Licenser committed Feb 2, 2025
1 parent dc8298d commit 9ae0790
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 147 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ wasmtest:
cargo clean --target-dir target
cargo build --tests --target wasm32-wasip1 --target-dir target
wasmtime run target/wasm32-wasip1/debug/deps/simd_json*.wasm
wasmtime run --dir=. target/wasm32-wasip1/debug/deps/jsonchecker*.wasm
wasmtime run --dir=. target/wasm32-wasip1/debug/deps/jsonchecker*.wasm
7 changes: 3 additions & 4 deletions src/impls/neon/deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,11 @@ pub(crate) fn parse_str<'invoke, 'de>(
// within the unicode codepoint handling code.
src_i += bs_dist as usize;
dst_i += bs_dist as usize;
let (o, s) = if let Ok(r) =
let Ok((o, s)) =
handle_unicode_codepoint(unsafe { src.get_kinda_unchecked(src_i..) }, unsafe {
buffer.get_kinda_unchecked_mut(dst_i..)
}) {
r
} else {
})
else {
return Err(Deserializer::error_c(src_i, 'u', InvalidUnicodeCodepoint));
};
if o == 0 {
Expand Down
7 changes: 3 additions & 4 deletions src/impls/simd128/deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,11 @@ pub(crate) fn parse_str<'invoke, 'de>(
// within the unicode codepoint handling code.
src_i += bs_dist as usize;
dst_i += bs_dist as usize;
let (o, s) = if let Ok(r) =
let Ok((o, s)) =
handle_unicode_codepoint(unsafe { src.get_kinda_unchecked(src_i..) }, unsafe {
buffer.get_kinda_unchecked_mut(dst_i..)
}) {
r
} else {
})
else {
return Err(Deserializer::error_c(src_i, 'u', InvalidUnicodeCodepoint));
};
if o == 0 {
Expand Down
6 changes: 2 additions & 4 deletions src/impls/sse42/deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,10 @@ pub(crate) unsafe fn parse_str<'invoke, 'de>(
// within the unicode codepoint handling code.
src_i += bs_dist as usize;
dst_i += bs_dist as usize;
let (o, s) = if let Ok(r) = handle_unicode_codepoint(
let Ok((o, s)) = handle_unicode_codepoint(
src.get_kinda_unchecked(src_i..),
buffer.get_kinda_unchecked_mut(dst_i..),
) {
r
} else {
) else {
return Err(Deserializer::error_c(src_i, 'u', InvalidUnicodeCodepoint));
};
if o == 0 {
Expand Down
10 changes: 4 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,16 +1029,14 @@ impl AlignedBuf {
/// Creates a new buffer that is aligned with the simd register size
#[must_use]
pub fn with_capacity(capacity: usize) -> Self {
let layout = match Layout::from_size_align(capacity, SIMDJSON_PADDING) {
Ok(layout) => layout,
Err(_) => Self::capacity_overflow(),
let Ok(layout) = Layout::from_size_align(capacity, SIMDJSON_PADDING) else {
Self::capacity_overflow()
};
if mem::size_of::<usize>() < 8 && capacity > isize::MAX as usize {
Self::capacity_overflow()
}
let inner = match unsafe { NonNull::new(alloc(layout)) } {
Some(ptr) => ptr,
None => handle_alloc_error(layout),
let Some(inner) = (unsafe { NonNull::new(alloc(layout)) }) else {
handle_alloc_error(layout)
};
Self {
layout,
Expand Down
14 changes: 4 additions & 10 deletions src/serde/value/borrowed/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,8 @@ impl<'de> de::Deserializer<'de> for Value<'de> {
let (variant, value) = match self {
Value::Object(value) => {
let mut iter = value.into_iter();
let (variant, value) = match iter.next() {
Some(v) => v,
None => {
return Err(crate::Deserializer::error(ErrorType::Eof));
}
let Some((variant, value)) = iter.next() else {
return Err(crate::Deserializer::error(ErrorType::Eof));
};
// enums are encoded in json as maps with a single key:value pair
if iter.next().is_some() {
Expand Down Expand Up @@ -687,11 +684,8 @@ impl<'de> de::Deserializer<'de> for &'de Value<'de> {
let (variant, value) = match self {
Value::Object(value) => {
let mut iter = value.iter();
let (variant, value) = match iter.next() {
Some(v) => v,
None => {
return Err(crate::Deserializer::error(ErrorType::Eof));
}
let Some((variant, value)) = iter.next() else {
return Err(crate::Deserializer::error(ErrorType::Eof));
};
// enums are encoded in json as maps with a single key:value pair
if iter.next().is_some() {
Expand Down
14 changes: 4 additions & 10 deletions src/serde/value/owned/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ impl<'de> de::Deserializer<'de> for Value {
let (variant, value) = match self {
Value::Object(value) => {
let mut iter = value.into_iter();
let (variant, value) = match iter.next() {
Some(v) => v,
None => {
return Err(crate::Deserializer::error(ErrorType::Eof));
}
let Some((variant, value)) = iter.next() else {
return Err(crate::Deserializer::error(ErrorType::Eof));
};
// enums are encoded in json as maps with a single key:value pair
if iter.next().is_some() {
Expand Down Expand Up @@ -675,11 +672,8 @@ impl<'de> de::Deserializer<'de> for &'de Value {
let (variant, value) = match self {
Value::Object(value) => {
let mut iter = value.iter();
let (variant, value) = match iter.next() {
Some(v) => v,
None => {
return Err(crate::Deserializer::error(ErrorType::Eof));
}
let Some((variant, value)) = iter.next() else {
return Err(crate::Deserializer::error(ErrorType::Eof));
};
// enums are encoded in json as maps with a single key:value pair
if iter.next().is_some() {
Expand Down
8 changes: 2 additions & 6 deletions src/stringparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,10 @@ pub(crate) fn get_unicode_codepoint(mut src_ptr: &[u8]) -> Result<(u32, usize),
if ((code_point | code_point_2) >> 16) != 0 {
return Ok((0, src_offset));
}
let c1 = if let Some(c) = code_point.checked_sub(0xd800) {
c
} else {
let Some(c1) = code_point.checked_sub(0xd800) else {
return Err(ErrorType::InvalidUtf8);
};
let c2 = if let Some(c) = code_point_2.checked_sub(0xdc00) {
c
} else {
let Some(c2) = code_point_2.checked_sub(0xdc00) else {
return Err(ErrorType::InvalidUtf8);
};
code_point = ((c1 << 10) | c2) + 0x10000;
Expand Down
34 changes: 17 additions & 17 deletions src/value/borrowed/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ impl<'v> PartialEq<bool> for Value<'v> {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn eq(&self, other: &bool) -> bool {
self.as_bool().map(|t| t.eq(other)).unwrap_or_default()
self.as_bool().is_some_and(|t| t.eq(other))
}
}

impl<'v> PartialEq<str> for Value<'v> {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn eq(&self, other: &str) -> bool {
self.as_str().map(|t| t.eq(other)).unwrap_or_default()
self.as_str().is_some_and(|t| t.eq(other))
}
}

Expand All @@ -73,111 +73,111 @@ impl<'v> PartialEq<String> for Value<'v> {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn eq(&self, other: &String) -> bool {
self.as_str().map(|t| t.eq(other)).unwrap_or_default()
self.as_str().is_some_and(|t| t.eq(other))
}
}

impl<'v> PartialEq<i8> for Value<'v> {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn eq(&self, other: &i8) -> bool {
self.as_i8().map(|t| t.eq(other)).unwrap_or_default()
self.as_i8().is_some_and(|t| t.eq(other))
}
}

impl<'v> PartialEq<i16> for Value<'v> {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn eq(&self, other: &i16) -> bool {
self.as_i16().map(|t| t.eq(other)).unwrap_or_default()
self.as_i16().is_some_and(|t| t.eq(other))
}
}

impl<'v> PartialEq<i32> for Value<'v> {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn eq(&self, other: &i32) -> bool {
self.as_i32().map(|t| t.eq(other)).unwrap_or_default()
self.as_i32().is_some_and(|t| t.eq(other))
}
}

impl<'v> PartialEq<i64> for Value<'v> {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn eq(&self, other: &i64) -> bool {
self.as_i64().map(|t| t.eq(other)).unwrap_or_default()
self.as_i64().is_some_and(|t| t.eq(other))
}
}

impl<'v> PartialEq<i128> for Value<'v> {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn eq(&self, other: &i128) -> bool {
self.as_i128().map(|t| t.eq(other)).unwrap_or_default()
self.as_i128().is_some_and(|t| t.eq(other))
}
}

impl<'v> PartialEq<u8> for Value<'v> {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn eq(&self, other: &u8) -> bool {
self.as_u8().map(|t| t.eq(other)).unwrap_or_default()
self.as_u8().is_some_and(|t| t.eq(other))
}
}

impl<'v> PartialEq<u16> for Value<'v> {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn eq(&self, other: &u16) -> bool {
self.as_u16().map(|t| t.eq(other)).unwrap_or_default()
self.as_u16().is_some_and(|t| t.eq(other))
}
}

impl<'v> PartialEq<u32> for Value<'v> {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn eq(&self, other: &u32) -> bool {
self.as_u32().map(|t| t.eq(other)).unwrap_or_default()
self.as_u32().is_some_and(|t| t.eq(other))
}
}

impl<'v> PartialEq<u64> for Value<'v> {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn eq(&self, other: &u64) -> bool {
self.as_u64().map(|t| t.eq(other)).unwrap_or_default()
self.as_u64().is_some_and(|t| t.eq(other))
}
}

impl<'v> PartialEq<usize> for Value<'v> {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn eq(&self, other: &usize) -> bool {
self.as_usize().map(|t| t.eq(other)).unwrap_or_default()
self.as_usize().is_some_and(|t| t.eq(other))
}
}

impl<'v> PartialEq<u128> for Value<'v> {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn eq(&self, other: &u128) -> bool {
self.as_u128().map(|t| t.eq(other)).unwrap_or_default()
self.as_u128().is_some_and(|t| t.eq(other))
}
}

impl<'v> PartialEq<f32> for Value<'v> {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn eq(&self, other: &f32) -> bool {
self.as_f32().map(|t| t.eq(other)).unwrap_or_default()
self.as_f32().is_some_and(|t| t.eq(other))
}
}

impl<'v> PartialEq<f64> for Value<'v> {
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn eq(&self, other: &f64) -> bool {
self.as_f64().map(|t| t.eq(other)).unwrap_or_default()
self.as_f64().is_some_and(|t| t.eq(other))
}
}

Expand All @@ -188,7 +188,7 @@ where
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn eq(&self, other: &&[T]) -> bool {
self.as_array().map(|t| t.eq(other)).unwrap_or_default()
self.as_array().is_some_and(|t| t.eq(other))
}
}

Expand Down
16 changes: 4 additions & 12 deletions src/value/borrowed/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ trait Generator: BaseGenerator {
stry!(self.write(b"{"));

// We know this exists since it's not empty
let (key, value) = if let Some(v) = iter.next() {
v
} else {
let Some((key, value)) = iter.next() else {
// We check against size
unreachable!();
};
Expand Down Expand Up @@ -107,9 +105,7 @@ trait Generator: BaseGenerator {
let mut iter = <[Value]>::iter(array);
// We know we have one item

let item = if let Some(v) = iter.next() {
v
} else {
let Some(item) = iter.next() else {
// We check against size
unreachable!();
};
Expand Down Expand Up @@ -146,9 +142,7 @@ trait FastGenerator: BaseGenerator {
stry!(self.write(b"{\""));

// We know this exists since it's not empty
let (key, value) = if let Some(v) = iter.next() {
v
} else {
let Some((key, value)) = iter.next() else {
// We check against size
unreachable!();
};
Expand Down Expand Up @@ -187,9 +181,7 @@ trait FastGenerator: BaseGenerator {
} else {
let mut iter = <[Value]>::iter(array);
// We know we have one item
let item = if let Some(v) = iter.next() {
v
} else {
let Some(item) = iter.next() else {
// We check against size
unreachable!();
};
Expand Down
Loading

0 comments on commit 9ae0790

Please sign in to comment.