Skip to content

Commit 7158644

Browse files
committed
fix clippy
Signed-off-by: Yang Zhang <yang.zhang@pingcap.com>
1 parent 7fe5013 commit 7158644

File tree

4 files changed

+18
-28
lines changed

4 files changed

+18
-28
lines changed

src/file_pipe_log/pipe_builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ impl<F: FileSystem> DualPipesBuilder<F> {
240240
self.scan_dir(&dir, lock)?;
241241
}
242242

243-
self.append_file_names.sort_by(|a, b| a.seq.cmp(&b.seq));
244-
self.rewrite_file_names.sort_by(|a, b| a.seq.cmp(&b.seq));
245-
self.recycled_file_names.sort_by(|a, b| a.seq.cmp(&b.seq));
243+
self.append_file_names.sort_by_key(|a| a.seq);
244+
self.rewrite_file_names.sort_by_key(|a| a.seq);
245+
self.recycled_file_names.sort_by_key(|a| a.seq);
246246
Ok(())
247247
}
248248

src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
#![cfg_attr(feature = "nightly", feature(test))]
1717
#![cfg_attr(feature = "swap", feature(allocator_api))]
1818
#![cfg_attr(feature = "swap", feature(slice_ptr_get))]
19-
// Though the new nightly rust stablized this feature, keep it anyway
20-
// because some other project (like TiKV) is still using the old.
21-
#![cfg_attr(feature = "swap", feature(nonnull_slice_from_raw_parts))]
22-
#![cfg_attr(feature = "swap", feature(slice_ptr_len))]
2319
#![cfg_attr(feature = "swap", feature(alloc_layout_extra))]
2420
#![cfg_attr(all(test, feature = "swap"), feature(alloc_error_hook))]
2521
#![cfg_attr(all(test, feature = "swap"), feature(cfg_sanitize))]

src/log_batch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,11 @@ impl LogItemBatch {
372372
self.items
373373
}
374374

375-
pub fn iter(&self) -> std::slice::Iter<LogItem> {
375+
pub fn iter(&self) -> std::slice::Iter<'_, LogItem> {
376376
self.items.iter()
377377
}
378378

379-
pub fn drain(&mut self) -> LogItemDrain {
379+
pub fn drain(&mut self) -> LogItemDrain<'_> {
380380
self.item_size = 0;
381381
self.entries_size = 0;
382382
self.checksum = 0;
@@ -882,7 +882,7 @@ impl LogBatch {
882882
}
883883

884884
/// Consumes log items into an iterator.
885-
pub(crate) fn drain(&mut self) -> LogItemDrain {
885+
pub(crate) fn drain(&mut self) -> LogItemDrain<'_> {
886886
debug_assert!(!matches!(self.buf_state, BufState::Incomplete));
887887

888888
self.buf.shrink_to(MAX_LOG_BATCH_BUFFER_CAP);

src/swappy_allocator.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ unsafe impl<A: Allocator + Send + Sync> Allocator for SwappyAllocator<A> {
144144
}
145145
}
146146
self.0.mem_usage.fetch_sub(layout.size(), Ordering::Relaxed);
147-
self.0.mem_allocator.deallocate(ptr, layout)
147+
unsafe { self.0.mem_allocator.deallocate(ptr, layout) }
148148
}
149149

150150
#[inline]
@@ -187,12 +187,9 @@ unsafe impl<A: Allocator + Send + Sync> Allocator for SwappyAllocator<A> {
187187

188188
Ok(new_ptr)
189189
} else {
190-
self.0
191-
.mem_allocator
192-
.grow(ptr, old_layout, new_layout)
193-
.inspect_err(|_| {
194-
self.0.mem_usage.fetch_sub(diff, Ordering::Relaxed);
195-
})
190+
unsafe { self.0.mem_allocator.grow(ptr, old_layout, new_layout) }.inspect_err(|_| {
191+
self.0.mem_usage.fetch_sub(diff, Ordering::Relaxed);
192+
})
196193
}
197194
}
198195

@@ -203,8 +200,8 @@ unsafe impl<A: Allocator + Send + Sync> Allocator for SwappyAllocator<A> {
203200
old_layout: Layout,
204201
new_layout: Layout,
205202
) -> Result<NonNull<[u8]>, AllocError> {
206-
let ptr = self.grow(ptr, old_layout, new_layout)?;
207-
ptr.as_non_null_ptr().as_ptr().write_bytes(0, ptr.len());
203+
let ptr = unsafe { self.grow(ptr, old_layout, new_layout)? };
204+
unsafe { ptr.as_non_null_ptr().as_ptr().write_bytes(0, ptr.len()) };
208205
Ok(ptr)
209206
}
210207

@@ -243,19 +240,16 @@ unsafe impl<A: Allocator + Send + Sync> Allocator for SwappyAllocator<A> {
243240
} else {
244241
// The new layout should still be mapped to disk. Reuse old pointer.
245242
Ok(NonNull::slice_from_raw_parts(
246-
NonNull::new_unchecked(ptr.as_ptr()),
243+
unsafe { NonNull::new_unchecked(ptr.as_ptr()) },
247244
new_layout.size(),
248245
))
249246
}
250247
} else {
251-
self.0
252-
.mem_allocator
253-
.shrink(ptr, old_layout, new_layout)
254-
.inspect(|_| {
255-
self.0
256-
.mem_usage
257-
.fetch_sub(old_layout.size() - new_layout.size(), Ordering::Relaxed);
258-
})
248+
unsafe { self.0.mem_allocator.shrink(ptr, old_layout, new_layout) }.inspect(|_| {
249+
self.0
250+
.mem_usage
251+
.fetch_sub(old_layout.size() - new_layout.size(), Ordering::Relaxed);
252+
})
259253
}
260254
}
261255
}

0 commit comments

Comments
 (0)