Skip to content

Commit 22fe803

Browse files
Seulgi Kimmergify[bot]
Seulgi Kim
authored andcommitted
Fix clippy warnings
1 parent 81a6de9 commit 22fe803

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

util/rlp/src/rlpin.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -186,25 +186,22 @@ where
186186
}
187187

188188
pub fn item_count(&self) -> Result<usize, DecoderError> {
189-
match self.is_list() {
190-
true => match self.count_cache.get() {
191-
Some(c) => Ok(c),
192-
None => {
193-
let c = self.iter().count();
194-
self.count_cache.set(Some(c));
195-
Ok(c)
196-
}
197-
},
198-
false => Err(DecoderError::RlpExpectedToBeList),
189+
if !self.is_list() {
190+
return Err(DecoderError::RlpExpectedToBeList)
199191
}
192+
Ok(self.count_cache.get().unwrap_or_else(|| {
193+
let c = self.iter().count();
194+
self.count_cache.set(Some(c));
195+
c
196+
}))
200197
}
201198

202199
pub fn size(&self) -> usize {
203-
match self.is_data() {
204-
// TODO: No panic on malformed data, but ideally would Err on no PayloadInfo.
205-
true => BasicDecoder::payload_info(self.bytes).map(|b| b.value_len).unwrap_or(0),
206-
false => 0,
200+
// TODO: No panic on malformed data, but ideally would Err on no PayloadInfo.
201+
if !self.is_data() {
202+
return 0
207203
}
204+
BasicDecoder::payload_info(self.bytes).map(|b| b.value_len).unwrap_or(0)
208205
}
209206

210207
pub fn at(&'view self, index: usize) -> Result<Rlp<'a>, DecoderError> {
@@ -215,9 +212,10 @@ where
215212
// move to cached position if its index is less or equal to
216213
// current search index, otherwise move to beginning of list
217214
let c = self.offset_cache.get();
218-
let (mut bytes, to_skip) = match c.index <= index {
219-
true => (Rlp::consume(self.bytes, c.offset)?, index - c.index),
220-
false => (self.consume_list_payload()?, index),
215+
let (mut bytes, to_skip) = if c.index <= index {
216+
(Rlp::consume(self.bytes, c.offset)?, index - c.index)
217+
} else {
218+
(self.consume_list_payload()?, index)
221219
};
222220

223221
// skip up to x items
@@ -235,17 +233,16 @@ where
235233
})
236234
}
237235

238-
239236
// update the cache
240-
self.offset_cache.set(OffsetCache::new(index, self.bytes.len() - bytes.len()));
237+
self.offset_cache.set(OffsetCache::new(index, new_offset));
241238

242239
// construct new rlp
243240
let found = BasicDecoder::payload_info(bytes)?;
244241
Ok(Rlp::new(&bytes[0..found.header_len + found.value_len]))
245242
}
246243

247244
pub fn is_null(&self) -> bool {
248-
self.bytes.len() == 0
245+
self.bytes.is_empty()
249246
}
250247

251248
pub fn is_empty(&self) -> bool {
@@ -325,12 +322,13 @@ where
325322

326323
/// consumes slice prefix of length `len`
327324
fn consume(bytes: &'a [u8], len: usize) -> Result<&'a [u8], DecoderError> {
328-
match bytes.len() >= len {
329-
true => Ok(&bytes[len..]),
330-
false => Err(DecoderError::RlpIsTooShort {
325+
if bytes.len() >= len {
326+
Ok(&bytes[len..])
327+
} else {
328+
Err(DecoderError::RlpIsTooShort {
331329
expected: len,
332330
got: bytes.len(),
333-
}),
331+
})
334332
}
335333
}
336334
}

0 commit comments

Comments
 (0)