Skip to content

Commit dd2bfee

Browse files
authored
Fix lints (#31)
1 parent 82b9ff5 commit dd2bfee

File tree

6 files changed

+55
-56
lines changed

6 files changed

+55
-56
lines changed

oscars/benches/arena2_vs_arena3.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ fn bench_small_objects(c: &mut Criterion) {
5353

5454
#[derive(Clone, Copy)]
5555
struct SmallObject {
56-
a: u64,
57-
b: u64,
56+
_a: u64,
57+
_b: u64,
5858
}
5959

6060
for num_objects in [100, 500, 1000].iter() {
@@ -68,8 +68,8 @@ fn bench_small_objects(c: &mut Criterion) {
6868

6969
for i in 0..num_objects {
7070
let obj = SmallObject {
71-
a: i as u64,
72-
b: i as u64 * 2,
71+
_a: i as u64,
72+
_b: i as u64 * 2,
7373
};
7474
let _ = allocator.try_alloc(obj).expect("allocation failed");
7575
}
@@ -89,8 +89,8 @@ fn bench_small_objects(c: &mut Criterion) {
8989

9090
for i in 0..num_objects {
9191
let obj = SmallObject {
92-
a: i as u64,
93-
b: i as u64 * 2,
92+
_a: i as u64,
93+
_b: i as u64 * 2,
9494
};
9595
let _ = allocator.try_alloc(obj).expect("allocation failed");
9696
}
@@ -154,11 +154,8 @@ fn bench_density(c: &mut Criterion) {
154154
oscars::alloc::arena3::ArenaAllocator::default().with_arena_size(PAGE_SIZE);
155155

156156
let mut count = 0;
157-
loop {
158-
match allocator.try_alloc([0u64; 2]) {
159-
Ok(_) => count += 1,
160-
Err(_) => break,
161-
}
157+
while allocator.try_alloc([0u64; 2]).is_ok() {
158+
count += 1;
162159
if allocator.arenas_len() > 1 {
163160
break;
164161
}
@@ -174,11 +171,8 @@ fn bench_density(c: &mut Criterion) {
174171
oscars::alloc::arena2::ArenaAllocator::default().with_arena_size(PAGE_SIZE);
175172

176173
let mut count = 0;
177-
loop {
178-
match allocator.try_alloc([0u64; 2]) {
179-
Ok(_) => count += 1,
180-
Err(_) => break,
181-
}
174+
while allocator.try_alloc([0u64; 2]).is_ok() {
175+
count += 1;
182176
if allocator.arenas_len() > 1 {
183177
break;
184178
}

oscars/src/alloc/arena3/alloc.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ impl<'arena> ErasedArenaPointer<'arena> {
3838
self.0
3939
}
4040

41-
// retype this pointer
42-
// SAFETY: caller must ensure `T` matches the original allocation
41+
/// Retype this pointer
42+
///
43+
/// # Safety
44+
///
45+
/// Caller must ensure `T` matches the original allocation
4346
pub unsafe fn to_typed_arena_pointer<T>(self) -> ArenaPointer<'arena, T> {
4447
ArenaPointer(self.0.cast::<ArenaHeapItem<T>>(), PhantomData)
4548
}
@@ -48,9 +51,11 @@ impl<'arena> ErasedArenaPointer<'arena> {
4851
self.0
4952
}
5053

51-
// extend the lifetime of this erased arena pointer to 'static
52-
//
53-
// SAFETY: same as ArenaPointer::extend_lifetime
54+
/// Extend the lifetime of this erased arena pointer to 'static
55+
///
56+
/// # Safety
57+
///
58+
/// Safe because the gc collector owns the arena and keeps it alive
5459
pub(crate) unsafe fn extend_lifetime(self) -> ErasedArenaPointer<'static> {
5560
ErasedArenaPointer(self.0, PhantomData)
5661
}
@@ -85,7 +90,7 @@ impl<'arena, T> ArenaPointer<'arena, T> {
8590
}
8691
}
8792

88-
/// SlotPool ///
93+
// ==== SlotPool ==== //
8994

9095
impl core::fmt::Debug for SlotPool {
9196
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
@@ -132,7 +137,7 @@ impl SlotPool {
132137
// example (512 capacity, 16 slot size): guess 32 slots -> 8 byte bitmap, real 504 bytes left -> 31 slots
133138
// layout: [ 8-byte bitmap ][ 31 x 16-byte slots ] = 504 bytes used
134139
let estimated = total_capacity / slot_size;
135-
let bitmap_words = (estimated + 63) / 64;
140+
let bitmap_words = estimated.div_ceil(64);
136141
let bitmap_bytes = bitmap_words * 8;
137142
let slot_area = total_capacity.saturating_sub(bitmap_bytes);
138143
let slot_count = slot_area / slot_size;

oscars/src/alloc/arena3/mod.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -129,30 +129,30 @@ impl<'alloc> ArenaAllocator<'alloc> {
129129
let cached_idx = self.alloc_cache[sc_idx].get();
130130
if cached_idx < self.typed_arenas.len() {
131131
let pool = &self.typed_arenas[cached_idx];
132-
if pool.slot_size == slot_size {
133-
if let Some(slot_ptr) = pool.alloc_slot() {
134-
// SAFETY: slot_ptr was successfully allocated for this size class
135-
return unsafe {
136-
let dst = slot_ptr.as_ptr() as *mut ArenaHeapItem<T>;
137-
dst.write(ArenaHeapItem(value));
138-
Ok(ArenaPointer::from_raw(NonNull::new_unchecked(dst)))
139-
};
140-
}
132+
if pool.slot_size == slot_size
133+
&& let Some(slot_ptr) = pool.alloc_slot()
134+
{
135+
// SAFETY: slot_ptr was successfully allocated for this size class
136+
return unsafe {
137+
let dst = slot_ptr.as_ptr() as *mut ArenaHeapItem<T>;
138+
dst.write(ArenaHeapItem(value));
139+
Ok(ArenaPointer::from_raw(NonNull::new_unchecked(dst)))
140+
};
141141
}
142142
}
143143

144144
// try existing pools with matching slot_size first
145145
for (i, pool) in self.typed_arenas.iter().enumerate().rev() {
146-
if pool.slot_size == slot_size {
147-
if let Some(slot_ptr) = pool.alloc_slot() {
148-
self.alloc_cache[sc_idx].set(i);
149-
// SAFETY: slot_ptr was successfully allocated for this size class
150-
return unsafe {
151-
let dst = slot_ptr.as_ptr() as *mut ArenaHeapItem<T>;
152-
dst.write(ArenaHeapItem(value));
153-
Ok(ArenaPointer::from_raw(NonNull::new_unchecked(dst)))
154-
};
155-
}
146+
if pool.slot_size == slot_size
147+
&& let Some(slot_ptr) = pool.alloc_slot()
148+
{
149+
self.alloc_cache[sc_idx].set(i);
150+
// SAFETY: slot_ptr was successfully allocated for this size class
151+
return unsafe {
152+
let dst = slot_ptr.as_ptr() as *mut ArenaHeapItem<T>;
153+
dst.write(ArenaHeapItem(value));
154+
Ok(ArenaPointer::from_raw(NonNull::new_unchecked(dst)))
155+
};
156156
}
157157
}
158158

@@ -173,11 +173,11 @@ impl<'alloc> ArenaAllocator<'alloc> {
173173
}
174174
}
175175

176-
// drops the value at `ptr` and returns the slot to the allocator
177-
//
178-
// SAFETY:
179-
// `ptr` must be a live `ArenaHeapItem<T>` allocated by this allocator,
180-
// must not be used after this call
176+
/// Drops the value at `ptr` and returns the slot to the allocator
177+
///
178+
/// # Safety
179+
/// `ptr` must be a live `ArenaHeapItem<T>` allocated by this allocator,
180+
/// must not be used after this call
181181
pub unsafe fn free_slot_typed<T>(&mut self, ptr: NonNull<ArenaHeapItem<T>>) {
182182
// SAFETY: guaranteed by caller
183183
unsafe { core::ptr::drop_in_place(ptr.as_ptr()) };
@@ -211,10 +211,10 @@ impl<'alloc> ArenaAllocator<'alloc> {
211211
// bump allocate raw bytes onto a BumpPage
212212
pub fn try_alloc_bytes(&mut self, layout: Layout) -> Result<NonNull<[u8]>, ArenaAllocError> {
213213
// try the most recent raw page first
214-
if let Some(page) = self.raw_arenas.last() {
215-
if let Ok(ptr) = page.try_alloc(layout) {
216-
return Ok(ptr);
217-
}
214+
if let Some(page) = self.raw_arenas.last()
215+
&& let Ok(ptr) = page.try_alloc(layout)
216+
{
217+
return Ok(ptr);
218218
}
219219
// allocate a new raw page with margin for padding
220220
let margin = 64;

oscars/src/collectors/mark_sweep/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ pub(crate) mod internals;
2626
pub mod gc_collections;
2727

2828
#[doc(hidden)]
29-
pub use pointers::weak_map::ErasedWeakMap;
30-
pub use pointers::weak_map::WeakMap;
31-
pub use pointers::{Gc, WeakGc};
29+
pub use pointers::ErasedWeakMap;
30+
pub use pointers::{Gc, WeakGc, WeakMap};
3231
pub use trace::{Finalize, Trace, TraceColor};
3332

3433
#[cfg(feature = "gc_allocator")]

oscars/src/collectors/mark_sweep/pointers/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ pub(crate) mod weak_map;
66

77
pub use gc::Gc;
88
pub use weak::WeakGc;
9+
pub use weak_map::{ErasedWeakMap, WeakMap};

oscars/src/collectors/mark_sweep/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ fn remove_wm() {
307307

308308
// remove should return true and leave map empty
309309
let removed = map.remove(&key.clone());
310-
assert_eq!(removed, true, "remove returned wrong value");
310+
assert!(removed, "remove returned wrong value");
311311
assert_eq!(
312312
map.get(&key.clone()),
313313
None,
@@ -380,7 +380,7 @@ fn remove_then_collect() {
380380

381381
map.insert(&key.clone(), 99u64, collector);
382382
let removed = map.remove(&key.clone());
383-
assert_eq!(removed, true);
383+
assert!(removed);
384384

385385
// the ephemeron stays in the queue until the key is collected
386386
drop(key);

0 commit comments

Comments
 (0)