From 962a3967efac1eb3331333761868126348b59db9 Mon Sep 17 00:00:00 2001 From: Arthur Silva Date: Mon, 6 Oct 2025 22:35:31 +0200 Subject: [PATCH 1/2] cargo fmt and clippy --- src/linked_slab.rs | 16 ++++++++++------ src/sync.rs | 3 +-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/linked_slab.rs b/src/linked_slab.rs index 97ced29..bd840da 100644 --- a/src/linked_slab.rs +++ b/src/linked_slab.rs @@ -107,17 +107,21 @@ impl LinkedSlab { /// Gets an entry and a token to the next entry w/o checking, thus unsafe. #[inline] pub unsafe fn get_unchecked(&self, index: Token) -> (&T, Token) { - let entry = self.entries.get_unchecked((index.get() - 1) as usize); - let v = entry.item.as_ref().unwrap_unchecked(); - (v, entry.next) + unsafe { + let entry = self.entries.get_unchecked((index.get() - 1) as usize); + let v = entry.item.as_ref().unwrap_unchecked(); + (v, entry.next) + } } /// Gets an entry and a token to the next entry w/o checking, thus unsafe. #[inline] pub unsafe fn get_mut_unchecked(&mut self, index: Token) -> (&mut T, Token) { - let entry = self.entries.get_unchecked_mut((index.get() - 1) as usize); - let v = entry.item.as_mut().unwrap_unchecked(); - (v, entry.next) + unsafe { + let entry = self.entries.get_unchecked_mut((index.get() - 1) as usize); + let v = entry.item.as_mut().unwrap_unchecked(); + (v, entry.next) + } } /// Links an entry before `target_head`. Returns the item next to the linked item, diff --git a/src/sync.rs b/src/sync.rs index 667cdaa..c42d0ad 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -271,8 +271,7 @@ impl< Q: Hash + Equivalent + ?Sized, { let (shard, hash) = self.shard_for(key).unwrap(); - let removed = shard.write().remove(hash, key); - removed + shard.write().remove(hash, key) } /// Inserts an item in the cache, but _only_ if an entry with key `key` already exists. From d08cc39cbc3073c3dcb48238f3ac4c531a6cbff8 Mon Sep 17 00:00:00 2001 From: Arthur Silva Date: Mon, 6 Oct 2025 22:52:51 +0200 Subject: [PATCH 2/2] Create tools dir --- .github/workflows/ci.yml | 5 +++++ .gitignore | 6 +++--- Cargo.toml | 2 -- tools/Cargo.toml | 14 ++++++++++++++ {examples => tools/src}/memory_used_plot.rs | 11 ++++++----- 5 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 tools/Cargo.toml rename {examples => tools/src}/memory_used_plot.rs (93%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1a9123..c92f86b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,6 +105,11 @@ jobs: with: command: clippy args: -- -D warnings + - name: Install dependencies for tools + run: sudo apt-get -y install libfontconfig1-dev jq + - name: Check tools + working-directory: tools + run: cargo clippy -- -D warnings miri: runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 8178a02..02d2a65 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -/target -/Cargo.lock -cache_memory_used.png \ No newline at end of file +**/target +**/Cargo.lock +**/cache_memory_used.png diff --git a/Cargo.toml b/Cargo.toml index 66e3d88..63f1482 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,8 +29,6 @@ criterion = "0.7" rand = { version = "0.9", features = ["small_rng"] } rand_distr = "0.5" tokio = { version = "1", features = ["full"] } -memory-stats = { version = "1.2.0" } -plotters = { version = "0.3" } [[bench]] name = "benchmarks" diff --git a/tools/Cargo.toml b/tools/Cargo.toml new file mode 100644 index 0000000..cacff27 --- /dev/null +++ b/tools/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "memory_used_plot" +version = "0.1.0" +edition = "2021" +publish = false + +[[bin]] +name = "memory_used_plot" +path = "src/memory_used_plot.rs" + +[dependencies] +quick_cache = { path = ".." } +memory-stats = "1.2.0" +plotters = "0.3" diff --git a/examples/memory_used_plot.rs b/tools/src/memory_used_plot.rs similarity index 93% rename from examples/memory_used_plot.rs rename to tools/src/memory_used_plot.rs index c8c6e6e..f5be995 100644 --- a/examples/memory_used_plot.rs +++ b/tools/src/memory_used_plot.rs @@ -38,7 +38,7 @@ fn main() { println!("{:?}", memory_data); memory_datas.push(memory_data); } - let key: Key = (n as u128).to_le_bytes().into(); + let key: Key = (n as u128).to_le_bytes(); cache.insert(key, ()); } @@ -62,8 +62,9 @@ fn main() { let mut chart = ChartBuilder::on(&root) .caption( format!( - "Memory Used ({})", - format!("{}(cap={})", type_name_of_val(&cache), cache_capacity) + "Memory Used ({}(cap={}))", + type_name_of_val(&cache), + cache_capacity ), ("sans-serif", 60), ) @@ -104,8 +105,8 @@ fn main() { chart .configure_series_labels() - .background_style(&WHITE.mix(0.8)) - .border_style(&BLACK) + .background_style(WHITE.mix(0.8)) + .border_style(BLACK) .label_font(("sans-serif", 20)) .legend_area_size(60) .draw()