From 00b2f168490972a0fb3498889077e193e3fea124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=9D=E5=80=89=E6=B0=B4=E5=B8=8C?= Date: Fri, 21 Nov 2025 11:36:29 +0800 Subject: [PATCH 1/2] feat: add Default impl, fix clippy warnings --- benches/collections.rs | 1 + src/bitmap.rs | 6 ++++++ src/buddy.rs | 6 ++++++ src/slab.rs | 6 ++++++ src/tlsf.rs | 6 ++++++ tests/allocator.rs | 2 +- 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/benches/collections.rs b/benches/collections.rs index c31fd84..6af3e2e 100644 --- a/benches/collections.rs +++ b/benches/collections.rs @@ -17,6 +17,7 @@ const POOL_SIZE: usize = 1024 * 1024 * 128; fn vec_push(n: usize, alloc: &(impl Allocator + Clone)) { let mut v: Vec = Vec::new_in(alloc.clone()); + #[allow(clippy::same_item_push)] for _ in 0..n { v.push(0xdead_beef); } diff --git a/src/bitmap.rs b/src/bitmap.rs index 0cbf995..7fcb841 100644 --- a/src/bitmap.rs +++ b/src/bitmap.rs @@ -50,6 +50,12 @@ impl BitmapPageAllocator { } } +impl Default for BitmapPageAllocator { + fn default() -> Self { + Self::new() + } +} + impl BaseAllocator for BitmapPageAllocator { fn init(&mut self, start: usize, size: usize) { assert!(PAGE_SIZE.is_power_of_two()); diff --git a/src/buddy.rs b/src/buddy.rs index 872f540..acd099b 100644 --- a/src/buddy.rs +++ b/src/buddy.rs @@ -24,6 +24,12 @@ impl BuddyByteAllocator { } } +impl Default for BuddyByteAllocator { + fn default() -> Self { + Self::new() + } +} + impl BaseAllocator for BuddyByteAllocator { fn init(&mut self, start: usize, size: usize) { unsafe { self.inner.init(start, size) }; diff --git a/src/slab.rs b/src/slab.rs index 17cb164..cfb4930 100644 --- a/src/slab.rs +++ b/src/slab.rs @@ -29,6 +29,12 @@ impl SlabByteAllocator { } } +impl Default for SlabByteAllocator { + fn default() -> Self { + Self::new() + } +} + impl BaseAllocator for SlabByteAllocator { fn init(&mut self, start: usize, size: usize) { self.inner = unsafe { Some(Heap::new(start, size)) }; diff --git a/src/tlsf.rs b/src/tlsf.rs index 3d2cd99..eb8b9aa 100644 --- a/src/tlsf.rs +++ b/src/tlsf.rs @@ -28,6 +28,12 @@ impl TlsfByteAllocator { } } +impl Default for TlsfByteAllocator { + fn default() -> Self { + Self::new() + } +} + impl BaseAllocator for TlsfByteAllocator { fn init(&mut self, start: usize, size: usize) { unsafe { diff --git a/tests/allocator.rs b/tests/allocator.rs index 58962b5..1b10080 100644 --- a/tests/allocator.rs +++ b/tests/allocator.rs @@ -64,7 +64,7 @@ pub fn test_alignment(n: usize, alloc: &(impl Allocator + Clone)) { let mut rng = rand::thread_rng(); let mut blocks = vec![]; for _ in 0..n { - if rng.gen_ratio(2, 3) || blocks.len() == 0 { + if rng.gen_ratio(2, 3) || blocks.is_empty() { // insert a block let size = ((1 << rng.gen_range(0..16)) as f32 * rng.gen_range(1.0..2.0)).round() as usize; From 0e3825827f7c77f8a611f775d9bfad20ae8c7e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=9D=E5=80=89=E6=B0=B4=E5=B8=8C?= Date: Fri, 21 Nov 2025 11:37:49 +0800 Subject: [PATCH 2/2] feat: bump version to 0.1.2 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 69614af..9698c13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "allocator" -version = "0.1.1" +version = "0.1.2" edition = "2021" authors = ["Yuekai Jia "] description = "Various allocator algorithms in a unified interface"