Skip to content

Commit de78de3

Browse files
committed
Fix clippy
Signed-off-by: Yang Zhang <yang.zhang@pingcap.com>
1 parent 458c431 commit de78de3

File tree

9 files changed

+16
-20
lines changed

9 files changed

+16
-20
lines changed

src/env/default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Read for LogFile {
6262
impl Seek for LogFile {
6363
fn seek(&mut self, pos: SeekFrom) -> IoResult<u64> {
6464
fail_point!("log_file::seek::err", |_| {
65-
Err(std::io::Error::new(std::io::ErrorKind::Other, "fp"))
65+
Err(std::io::Error::other("fp"))
6666
});
6767
match pos {
6868
SeekFrom::Start(offset) => self.offset = offset as usize,

src/file_pipe_log/log_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<F: FileSystem> LogFileWriter<F> {
107107
}
108108
self.capacity += alloc;
109109
}
110-
self.writer.write_all(buf).map_err(|e| {
110+
self.writer.write_all(buf).inspect_err(|e| {
111111
self.writer
112112
.seek(SeekFrom::Start(self.written as u64))
113113
.unwrap_or_else(|e| {

src/file_pipe_log/pipe_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl<F: FileSystem> DualPipesBuilder<F> {
379379
fn recover_queue_imp<M: ReplayMachine, FA: Factory<M>>(
380380
file_system: Arc<F>,
381381
recovery_cfg: RecoveryConfig,
382-
files: &mut Vec<File<F>>,
382+
files: &mut [File<F>],
383383
machine_factory: &FA,
384384
) -> Result<M> {
385385
if recovery_cfg.concurrency == 0 || files.is_empty() {
@@ -390,7 +390,7 @@ impl<F: FileSystem> DualPipesBuilder<F> {
390390
let recovery_mode = recovery_cfg.mode;
391391
let recovery_read_block_size = recovery_cfg.read_block_size as usize;
392392

393-
let max_chunk_size = std::cmp::max((files.len() + concurrency - 1) / concurrency, 1);
393+
let max_chunk_size = files.len().div_ceil(concurrency);
394394
let chunks = files.par_chunks_mut(max_chunk_size);
395395
let chunk_count = chunks.len();
396396
debug_assert!(chunk_count <= concurrency);

src/log_batch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
use std::fmt::Debug;
44
use std::io::BufRead;
5+
use std::mem;
56
use std::sync::atomic::{AtomicU64, Ordering};
67
use std::sync::Arc;
7-
use std::{mem, u64};
88

99
use byteorder::{BigEndian, LittleEndian, ReadBytesExt, WriteBytesExt};
1010
use log::error;
@@ -53,7 +53,7 @@ pub enum CompressionType {
5353
impl CompressionType {
5454
pub fn from_u8(t: u8) -> Result<Self> {
5555
if t <= CompressionType::Lz4 as u8 {
56-
Ok(unsafe { mem::transmute(t) })
56+
Ok(unsafe { mem::transmute::<u8, Self>(t) })
5757
} else {
5858
Err(Error::Corruption(format!(
5959
"Unrecognized compression type: {t}"
@@ -168,7 +168,7 @@ pub enum OpType {
168168
impl OpType {
169169
pub fn from_u8(t: u8) -> Result<Self> {
170170
if t <= OpType::Del as u8 {
171-
Ok(unsafe { mem::transmute(t) })
171+
Ok(unsafe { mem::transmute::<u8, Self>(t) })
172172
} else {
173173
Err(Error::Corruption(format!("Unrecognized op type: {t}")))
174174
}

src/memtable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl<A: AllocatorTrait> MemTable<A> {
228228
}
229229

230230
if let Some(g) = rhs.atomic_group.take() {
231-
assert!(self.atomic_group.map_or(true, |(_, end)| end <= g.0));
231+
assert!(self.atomic_group.is_none_or(|(_, end)| end <= g.0));
232232
self.atomic_group = Some(g);
233233
}
234234

@@ -545,7 +545,7 @@ impl<A: AllocatorTrait> MemTable<A> {
545545
}
546546

547547
pub fn apply_rewrite_atomic_group(&mut self, start: FileSeq, end: FileSeq) {
548-
assert!(self.atomic_group.map_or(true, |(_, b)| b <= start));
548+
assert!(self.atomic_group.is_none_or(|(_, b)| b <= start));
549549
self.atomic_group = Some((start, end));
550550
}
551551

@@ -763,7 +763,7 @@ impl<A: AllocatorTrait> MemTable<A> {
763763
debug_assert!(count > 0);
764764
self.entry_indexes
765765
.get(count - 1)
766-
.map_or(false, |ei| ei.entries.unwrap().id.seq <= gate.seq)
766+
.is_some_and(|ei| ei.entries.unwrap().id.seq <= gate.seq)
767767
}
768768

769769
/// Returns the region ID.

src/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub trait TimeMetric {
122122
}
123123
}
124124

125-
impl<'a> TimeMetric for &'a Histogram {
125+
impl TimeMetric for &Histogram {
126126
fn observe(&self, duration: Duration) {
127127
Histogram::observe(self, duration.as_secs_f64());
128128
}

src/swappy_allocator.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ unsafe impl<A: Allocator + Send + Sync> Allocator for SwappyAllocator<A> {
120120
return swap_r;
121121
}
122122
}
123-
self.0.mem_allocator.allocate(layout).map_err(|e| {
123+
self.0.mem_allocator.allocate(layout).inspect_err(|_| {
124124
self.0.mem_usage.fetch_sub(layout.size(), Ordering::Relaxed);
125-
e
126125
})
127126
}
128127

@@ -191,9 +190,8 @@ unsafe impl<A: Allocator + Send + Sync> Allocator for SwappyAllocator<A> {
191190
self.0
192191
.mem_allocator
193192
.grow(ptr, old_layout, new_layout)
194-
.map_err(|e| {
193+
.inspect_err(|_| {
195194
self.0.mem_usage.fetch_sub(diff, Ordering::Relaxed);
196-
e
197195
})
198196
}
199197
}
@@ -253,11 +251,10 @@ unsafe impl<A: Allocator + Send + Sync> Allocator for SwappyAllocator<A> {
253251
self.0
254252
.mem_allocator
255253
.shrink(ptr, old_layout, new_layout)
256-
.map(|p| {
254+
.inspect(|_| {
257255
self.0
258256
.mem_usage
259257
.fetch_sub(old_layout.size() - new_layout.size(), Ordering::Relaxed);
260-
p
261258
})
262259
}
263260
}

src/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pub fn unhash_u64(mut i: u64) -> u64 {
221221

222222
pub mod lz4 {
223223
use crate::{Error, Result};
224-
use std::{i32, ptr};
224+
use std::ptr;
225225

226226
pub const DEFAULT_LZ4_COMPRESSION_LEVEL: usize = 1;
227227

@@ -330,7 +330,7 @@ pub trait Factory<Target>: Send + Sync {
330330
/// ```
331331
#[inline]
332332
pub fn round_up(offset: usize, alignment: usize) -> usize {
333-
(offset + alignment - 1) / alignment * alignment
333+
offset.div_ceil(alignment) * alignment
334334
}
335335

336336
/// Returns an aligned `offset`.

src/write_barrier.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use crate::PerfContext;
1717

1818
type Ptr<T> = Option<NonNull<T>>;
1919

20-
///
2120
pub struct Writer<P, O> {
2221
next: Cell<Ptr<Writer<P, O>>>,
2322
payload: *mut P,

0 commit comments

Comments
 (0)