Skip to content

Commit 613e886

Browse files
committed
Add capacity() method to LinkedList, and bump version to 6.2.3
1 parent b831ffc commit 613e886

5 files changed

Lines changed: 1037 additions & 19 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cachebox"
3-
version = "6.2.2"
3+
version = "6.2.3"
44
edition = "2021"
55
description = "The fastest memoizing and caching Python library written in Rust"
66
readme = "README.md"
@@ -26,22 +26,11 @@ allocator-api2 = "0.4.0"
2626
cfg-if = "1.0.4"
2727
chrono = "0.4.45"
2828
fastrand = "2.5.0"
29-
parking_lot = {
30-
version = "0.12.5",
31-
default-features = false,
32-
}
33-
pyo3 = {
34-
version = "0.29.1",
35-
default-features = false,
36-
features = ["macros", "chrono"],
37-
}
29+
parking_lot = { version = "0.12.5", default-features = false }
30+
pyo3 = { version = "0.29.1", default-features = false, features = ["macros", "chrono"] }
3831

3932
[build-dependencies]
40-
pyo3-build-config = {
41-
version = "0.29.1",
42-
default-features = false,
43-
features = ["resolve-config"],
44-
}
33+
pyo3-build-config = { version = "0.29.1", default-features = false, features = ["resolve-config"] }
4534

4635
[features]
4736
default = ["inline-more", "extension-module"]

src/internal/linked_list.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,18 +314,22 @@ impl<T> LinkedList<T> {
314314

315315
/// Returns `true` if the list contains no elements.
316316
#[inline]
317-
#[must_use]
318317
pub fn is_empty(&self) -> bool {
319318
self.len == 0
320319
}
321320

322321
/// Returns the number of elements in the list.
323322
#[inline]
324-
#[must_use]
325323
pub fn len(&self) -> usize {
326324
self.len
327325
}
328326

327+
/// Returns the number of elements in the list.
328+
#[inline]
329+
pub fn capacity(&self) -> usize {
330+
self.len + self.free_len
331+
}
332+
329333
/// Removes all elements, dropping each element's value.
330334
#[inline]
331335
pub fn clear(&mut self) {

src/pyclasses/lrucache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl PyLRUCache {
173173
let inner = self.0.get();
174174
let policy = inner.policy();
175175

176-
policy.table().capacity()
176+
policy.table().capacity().max(policy.list().capacity())
177177
}
178178

179179
/// Returns the number of entries currently in the cache.

0 commit comments

Comments
 (0)