Skip to content

Commit a2950b2

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

File tree

16 files changed

+102
-149
lines changed

16 files changed

+102
-149
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ wasmtest:
1010
cargo clean --target-dir target
1111
cargo build --tests --target wasm32-wasip1 --target-dir target
1212
wasmtime run target/wasm32-wasip1/debug/deps/simd_json*.wasm
13-
wasmtime run --dir=. target/wasm32-wasip1/debug/deps/jsonchecker*.wasm
13+
wasmtime run --dir=. target/wasm32-wasip1/debug/deps/jsonchecker*.wasm

src/impls/neon/deser.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,11 @@ pub(crate) fn parse_str<'invoke, 'de>(
168168
// within the unicode codepoint handling code.
169169
src_i += bs_dist as usize;
170170
dst_i += bs_dist as usize;
171-
let (o, s) = if let Ok(r) =
171+
let Ok((o, s)) =
172172
handle_unicode_codepoint(unsafe { src.get_kinda_unchecked(src_i..) }, unsafe {
173173
buffer.get_kinda_unchecked_mut(dst_i..)
174-
}) {
175-
r
176-
} else {
174+
})
175+
else {
177176
return Err(Deserializer::error_c(src_i, 'u', InvalidUnicodeCodepoint));
178177
};
179178
if o == 0 {

src/impls/simd128/deser.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,11 @@ pub(crate) fn parse_str<'invoke, 'de>(
136136
// within the unicode codepoint handling code.
137137
src_i += bs_dist as usize;
138138
dst_i += bs_dist as usize;
139-
let (o, s) = if let Ok(r) =
139+
let Ok((o, s)) =
140140
handle_unicode_codepoint(unsafe { src.get_kinda_unchecked(src_i..) }, unsafe {
141141
buffer.get_kinda_unchecked_mut(dst_i..)
142-
}) {
143-
r
144-
} else {
142+
})
143+
else {
145144
return Err(Deserializer::error_c(src_i, 'u', InvalidUnicodeCodepoint));
146145
};
147146
if o == 0 {

src/impls/sse42/deser.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,10 @@ pub(crate) unsafe fn parse_str<'invoke, 'de>(
141141
// within the unicode codepoint handling code.
142142
src_i += bs_dist as usize;
143143
dst_i += bs_dist as usize;
144-
let (o, s) = if let Ok(r) = handle_unicode_codepoint(
144+
let Ok((o, s)) = handle_unicode_codepoint(
145145
src.get_kinda_unchecked(src_i..),
146146
buffer.get_kinda_unchecked_mut(dst_i..),
147-
) {
148-
r
149-
} else {
147+
) else {
150148
return Err(Deserializer::error_c(src_i, 'u', InvalidUnicodeCodepoint));
151149
};
152150
if o == 0 {

src/known_key.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ where
6060
let key = Cow::from(key);
6161
let hash_builder = NotSoRandomState::default();
6262
let mut hasher = hash_builder.build_hasher();
63-
key.hash(&mut hasher);
6463
Self {
65-
hash: hasher.finish(),
64+
hash: hash_builder.hash_one(&key),
6665
key,
6766
}
6867
}

src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,16 +1029,14 @@ impl AlignedBuf {
10291029
/// Creates a new buffer that is aligned with the simd register size
10301030
#[must_use]
10311031
pub fn with_capacity(capacity: usize) -> Self {
1032-
let layout = match Layout::from_size_align(capacity, SIMDJSON_PADDING) {
1033-
Ok(layout) => layout,
1034-
Err(_) => Self::capacity_overflow(),
1032+
let Ok(layout) = Layout::from_size_align(capacity, SIMDJSON_PADDING) else {
1033+
Self::capacity_overflow()
10351034
};
10361035
if mem::size_of::<usize>() < 8 && capacity > isize::MAX as usize {
10371036
Self::capacity_overflow()
10381037
}
1039-
let inner = match unsafe { NonNull::new(alloc(layout)) } {
1040-
Some(ptr) => ptr,
1041-
None => handle_alloc_error(layout),
1038+
let Some(inner) = (unsafe { NonNull::new(alloc(layout)) }) else {
1039+
handle_alloc_error(layout)
10421040
};
10431041
Self {
10441042
layout,

src/serde/value/borrowed/de.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,8 @@ impl<'de> de::Deserializer<'de> for Value<'de> {
8181
let (variant, value) = match self {
8282
Value::Object(value) => {
8383
let mut iter = value.into_iter();
84-
let (variant, value) = match iter.next() {
85-
Some(v) => v,
86-
None => {
87-
return Err(crate::Deserializer::error(ErrorType::Eof));
88-
}
84+
let Some((variant, value)) = iter.next() else {
85+
return Err(crate::Deserializer::error(ErrorType::Eof));
8986
};
9087
// enums are encoded in json as maps with a single key:value pair
9188
if iter.next().is_some() {
@@ -687,11 +684,8 @@ impl<'de> de::Deserializer<'de> for &'de Value<'de> {
687684
let (variant, value) = match self {
688685
Value::Object(value) => {
689686
let mut iter = value.iter();
690-
let (variant, value) = match iter.next() {
691-
Some(v) => v,
692-
None => {
693-
return Err(crate::Deserializer::error(ErrorType::Eof));
694-
}
687+
let Some((variant, value)) = iter.next() else {
688+
return Err(crate::Deserializer::error(ErrorType::Eof));
695689
};
696690
// enums are encoded in json as maps with a single key:value pair
697691
if iter.next().is_some() {

src/serde/value/owned/de.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,8 @@ impl<'de> de::Deserializer<'de> for Value {
6969
let (variant, value) = match self {
7070
Value::Object(value) => {
7171
let mut iter = value.into_iter();
72-
let (variant, value) = match iter.next() {
73-
Some(v) => v,
74-
None => {
75-
return Err(crate::Deserializer::error(ErrorType::Eof));
76-
}
72+
let Some((variant, value)) = iter.next() else {
73+
return Err(crate::Deserializer::error(ErrorType::Eof));
7774
};
7875
// enums are encoded in json as maps with a single key:value pair
7976
if iter.next().is_some() {
@@ -675,11 +672,8 @@ impl<'de> de::Deserializer<'de> for &'de Value {
675672
let (variant, value) = match self {
676673
Value::Object(value) => {
677674
let mut iter = value.iter();
678-
let (variant, value) = match iter.next() {
679-
Some(v) => v,
680-
None => {
681-
return Err(crate::Deserializer::error(ErrorType::Eof));
682-
}
675+
let Some((variant, value)) = iter.next() else {
676+
return Err(crate::Deserializer::error(ErrorType::Eof));
683677
};
684678
// enums are encoded in json as maps with a single key:value pair
685679
if iter.next().is_some() {

src/stringparse.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,10 @@ pub(crate) fn get_unicode_codepoint(mut src_ptr: &[u8]) -> Result<(u32, usize),
7171
if ((code_point | code_point_2) >> 16) != 0 {
7272
return Ok((0, src_offset));
7373
}
74-
let c1 = if let Some(c) = code_point.checked_sub(0xd800) {
75-
c
76-
} else {
74+
let Some(c1) = code_point.checked_sub(0xd800) else {
7775
return Err(ErrorType::InvalidUtf8);
7876
};
79-
let c2 = if let Some(c) = code_point_2.checked_sub(0xdc00) {
80-
c
81-
} else {
77+
let Some(c2) = code_point_2.checked_sub(0xdc00) else {
8278
return Err(ErrorType::InvalidUtf8);
8379
};
8480
code_point = ((c1 << 10) | c2) + 0x10000;

src/value/borrowed/cmp.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ impl<'v> PartialEq<bool> for Value<'v> {
4949
#[cfg_attr(not(feature = "no-inline"), inline)]
5050
#[must_use]
5151
fn eq(&self, other: &bool) -> bool {
52-
self.as_bool().map(|t| t.eq(other)).unwrap_or_default()
52+
self.as_bool().is_some_and(|t| t.eq(other))
5353
}
5454
}
5555

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)