Skip to content

Commit

Permalink
Remove the heapsize feature
Browse files Browse the repository at this point in the history
It is not exposed, so never compiled. It's leftover from when
lru_disk_cache was a separate crate.
  • Loading branch information
glandium committed Jul 17, 2024
1 parent 901923b commit f571231
Showing 1 changed file with 0 additions and 53 deletions.
53 changes: 0 additions & 53 deletions src/lru_disk_cache/lru_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@
//! assert!(cache.get_mut(&2).is_none());
//! ```
//!
//! The cache can also be limited by an arbitrary metric calculated from its key-value pairs, see
//! [`LruCache::with_meter`][with_meter] for more information. If the `heapsize` feature is enabled,
//! this crate provides one such alternate metric—`HeapSize`. Custom metrics can be written by
//! implementing the [`Meter`][meter] trait.
//!
//! [with_meter]: struct.LruCache.html#method.with_meter
//! [meter]: trait.Meter.html

#[cfg(feature = "heapsize")]
extern crate heapsize;

use std::borrow::Borrow;
use std::collections::hash_map::RandomState;
use std::fmt;
Expand Down Expand Up @@ -153,33 +142,6 @@ impl<K, V> CountableMeterWithMeasure<K, V, ()> for Count {
}
}

#[cfg(feature = "heapsize")]
mod heap_meter {
use heapsize::HeapSizeOf;
use std::borrow::Borrow;

/// Size limit based on the heap size of each cache item.
///
/// Requires cache entries that implement [`HeapSizeOf`][1].
///
/// [1]: https://doc.servo.org/heapsize/trait.HeapSizeOf.html
pub struct HeapSize;

impl<K, V: HeapSizeOf> super::Meter<K, V> for HeapSize {
type Measure = usize;

fn measure<Q: ?Sized>(&self, _: &Q, item: &V) -> usize
where
K: Borrow<Q>,
{
item.heap_size_of_children() + ::std::mem::size_of::<V>()
}
}
}

#[cfg(feature = "heapsize")]
pub use heap_meter::*;

/// An LRU cache.
#[derive(Clone)]
pub struct LruCache<K: Eq + Hash, V, S: BuildHasher = RandomState, M: CountableMeter<K, V> = Count>
Expand Down Expand Up @@ -906,19 +868,4 @@ mod tests {
assert!(!cache.contains_key("foo1"));
assert!(!cache.contains_key("foo2"));
}

#[cfg(feature = "heapsize")]
#[test]
fn test_heapsize_cache() {
use super::HeapSize;

let mut cache = LruCache::<&str, (u8, u8, u8), _, _>::with_meter(8, HeapSize);
cache.insert("foo1", (1, 2, 3));
cache.insert("foo2", (4, 5, 6));
cache.insert("foo3", (7, 8, 9));
assert!(!cache.contains_key("foo1"));
cache.insert("foo2", (10, 11, 12));
cache.insert("foo4", (13, 14, 15));
assert!(!cache.contains_key("foo3"));
}
}

0 comments on commit f571231

Please sign in to comment.