Skip to content

Commit 855bf1b

Browse files
committed
cargofmt and clippy
Signed-off-by: Jakub Sztandera <[email protected]>
1 parent 5d666a2 commit 855bf1b

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

ipld/bitfield/benches/benchmarks/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod examples;
55

66
use std::fs;
77
use std::path::Path;
8+
89
use criterion::{black_box, criterion_group, criterion_main, Criterion};
910
use examples::{example1, example2};
1011
use fvm_ipld_bitfield::BitField;
@@ -15,7 +16,7 @@ struct Profiler;
1516
impl criterion::profiler::Profiler for Profiler {
1617
fn start_profiling(&mut self, benchmark_id: &str, benchmark_dir: &Path) {
1718
fs::create_dir_all(benchmark_dir).unwrap();
18-
let bench_file =benchmark_id.to_owned() + ".prof";
19+
let bench_file = benchmark_id.to_owned() + ".prof";
1920
let bench_path = benchmark_dir.join(bench_file);
2021
let bench_str = bench_path.to_str().unwrap();
2122

@@ -28,10 +29,9 @@ impl criterion::profiler::Profiler for Profiler {
2829
}
2930

3031
fn profiled() -> Criterion {
31-
Criterion::default().with_profiler(Profiler{})
32+
Criterion::default().with_profiler(Profiler {})
3233
}
3334

34-
3535
fn len(c: &mut Criterion) {
3636
let bf = example1();
3737
c.bench_function("len", |b| b.iter(|| black_box(&bf).len()));
@@ -54,9 +54,7 @@ fn decode_encode(c: &mut Criterion) {
5454
});
5555
}
5656
fn decode(c: &mut Criterion) {
57-
c.bench_function("decode", |b| {
58-
b.iter(|| example1())
59-
});
57+
c.bench_function("decode", |b| b.iter(|| example1()));
6058
}
6159

6260
fn from_ranges(c: &mut Criterion) {

ipld/bitfield/src/rleplus/reader.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'a> BitReader<'a> {
3131
let mut bits = 0u64;
3232
for i in 0..2 {
3333
let byte = bytes.get(i).unwrap_or(&0);
34-
bits |= (*byte as u64) << (8*i);
34+
bits |= (*byte as u64) << (8 * i);
3535
}
3636

3737
let bytes = bytes.get(2..).unwrap_or(&[]);
@@ -62,7 +62,6 @@ impl<'a> BitReader<'a> {
6262
self.bits >>= num_bits;
6363
self.num_bits -= num_bits;
6464

65-
6665
// not sure why this being outside of the if improves the performance
6766
// bit it does, probably related to keeping caches warm
6867
let byte = self.bytes.get(0).unwrap_or(&0);
@@ -122,28 +121,26 @@ impl<'a> BitReader<'a> {
122121

123122
let peek6 = self.peek(6);
124123

125-
let len = if peek6 & 0b1 != 0 {
124+
let len = if peek6 & 0b01 != 0 {
126125
// Block Single (prefix 1)
127126
self.drop(1);
128127
1
128+
} else if peek6 & 0b10 != 0 {
129+
// Block Short (prefix 01)
130+
let val = ((peek6 >> 2) & 0x0f) as u64;
131+
self.drop(6);
132+
if val < 2 {
133+
return Err(Error::NotMinimal);
134+
}
135+
val
129136
} else {
130-
if peek6 & 0b10 != 0 {
131-
// Block Short (prefix 01)
132-
let val = ((peek6 >> 2) & 0x0f) as u64;
133-
self.drop(6);
134-
if val < 2 {
135-
return Err(Error::NotMinimal);
136-
}
137-
val
138-
} else {
139-
// Block Long (prefix 00)
140-
self.drop(2);
141-
let val = self.read_varint()?;
142-
if val < 16 {
143-
return Err(Error::NotMinimal);
144-
}
145-
val
137+
// Block Long (prefix 00)
138+
self.drop(2);
139+
let val = self.read_varint()?;
140+
if val < 16 {
141+
return Err(Error::NotMinimal);
146142
}
143+
val
147144
};
148145

149146
Ok(Some(len))

0 commit comments

Comments
 (0)