From 23a8b06322e0108d675503075197f6b40e401cf6 Mon Sep 17 00:00:00 2001 From: gmryuuko Date: Sat, 22 Jun 2024 20:45:54 +0800 Subject: [PATCH] fix: compile in stable --- src/arena.rs | 3 --- src/boxedset.rs | 11 ++++++----- src/intern.rs | 27 +++++++++++++++------------ 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/arena.rs b/src/arena.rs index ba40fc4..b361bb8 100644 --- a/src/arena.rs +++ b/src/arena.rs @@ -2,7 +2,6 @@ use crate::boxedset::HashSet; use std::borrow::Borrow; use std::hash::{Hash, Hasher}; -use std::ops::Deref; use std::sync::Mutex; /// A arena for storing interned data @@ -46,8 +45,6 @@ pub struct Arena { #[cfg(feature = "deepsize")] impl deepsize::DeepSizeOf for Arena { fn deep_size_of_children(&self, context: &mut deepsize::Context) -> usize { - use deepsize::DeepSizeOf; - let hashset = self.data.lock().unwrap(); (*hashset).deep_size_of_children(context) } diff --git a/src/boxedset.rs b/src/boxedset.rs index 062152a..15c98ec 100644 --- a/src/boxedset.rs +++ b/src/boxedset.rs @@ -20,24 +20,24 @@ impl

HashSet

{ #[cfg(feature = "deepsize")] impl deepsize::DeepSizeOf for HashSet<&'static P> { fn deep_size_of_children(&self, context: &mut deepsize::Context) -> usize { - let pointers = self.0.capacity() * size_of::<&'static P>(); + let pointers = self.0.capacity() * std::mem::size_of::<&'static P>(); let heap_memory = self .0 .keys() - .map(|n| (**n).deep_size_of_children(context) + size_of::

()) + .map(|n| (**n).deep_size_of_children(context) + std::mem::size_of::

()) .sum::(); pointers + heap_memory } } #[cfg(feature = "deepsize")] -impl deepsize::DeepSizeOf for HashSet> { +impl deepsize::DeepSizeOf for HashSet> { fn deep_size_of_children(&self, context: &mut deepsize::Context) -> usize { - let pointers = self.0.capacity() * size_of::>(); + let pointers = self.0.capacity() * std::mem::size_of::>(); let heap_memory = self .0 .keys() - .map(|n| (**n).deep_size_of_children(context) + size_of_val(&**n)) + .map(|n| (**n).deep_size_of_children(context) + std::mem::size_of_val(&**n)) .sum::(); pointers + heap_memory } @@ -77,6 +77,7 @@ impl HashSet

{ pub fn len(&self) -> usize { self.0.len() } + #[allow(dead_code)] // maybe unused without `deepsize` feature pub fn capacity(&self) -> usize { self.0.capacity() } diff --git a/src/intern.rs b/src/intern.rs index f93d311..4e84656 100644 --- a/src/intern.rs +++ b/src/intern.rs @@ -523,8 +523,8 @@ mod intern_tests { #[test] fn test_deep_size() { let string1 = String::from("abcdefghijklmnopqrstuvwxyz"); - let string2 = String::from("abcdefghijklmnopqrstuvwxyz"); - let string3 = String::from("abcdefghijklmnopqrstuvwxyz"); + let string2 = string1.clone(); + let string3 = string1.clone(); // 3 string are the same, interned only once let string_size = string1.deep_size_of(); @@ -532,10 +532,12 @@ mod intern_tests { let _ = Intern::new(string2); let _ = Intern::new(string3); // size of set - let set_size = INTERN_CONTAINERS.with(|m: &mut HashSet<&'static String>| size_of_val(m)); + let set_size = + INTERN_CONTAINERS.with(|m: &mut HashSet<&'static String>| std::mem::size_of_val(m)); // size of pointers in the set - let pointers_in_set_size = INTERN_CONTAINERS - .with(|m: &mut HashSet<&'static String>| size_of::<&'static String>() * m.capacity()); + let pointers_in_set_size = INTERN_CONTAINERS.with(|m: &mut HashSet<&'static String>| { + std::mem::size_of::<&'static String>() * m.capacity() + }); let interned_size = deep_size_of_interned::(); assert_eq!(interned_size, string_size + set_size + pointers_in_set_size); @@ -596,33 +598,34 @@ mod intern_tests { pointer: a1.pointer.clone(), }; // size of ArcInside, 16 bytes each - let object_size = size_of::() * 3; + let object_size = std::mem::size_of::() * 3; let _ = Intern::new(a1); let _ = Intern::new(a2); let _ = Intern::new(a3); // size of set - let set_size = INTERN_CONTAINERS.with(|m: &mut HashSet<&'static ArcInside>| size_of_val(m)); + let set_size = + INTERN_CONTAINERS.with(|m: &mut HashSet<&'static ArcInside>| std::mem::size_of_val(m)); // size of pointers in the set let pointers_in_set_size = INTERN_CONTAINERS.with(|m: &mut HashSet<&'static ArcInside>| { - size_of::<&'static ArcInside>() * m.capacity() + std::mem::size_of::<&'static ArcInside>() * m.capacity() }); // 3 ArcInside has different hash values INTERN_CONTAINERS.with(|m: &mut HashSet<&'static ArcInside>| assert_eq!(m.len(), 3)); let interned_size = deep_size_of_interned::(); - assert_eq!( - interned_size, - string_size + object_size + set_size + pointers_in_set_size - ); println!("string_size: {}", string_size); println!("object_size: {}", object_size); println!("set_size: {}", set_size); println!("pointers_in_set_size: {}", pointers_in_set_size); println!("interned_size: {}", interned_size); + assert_eq!( + interned_size, + string_size + object_size + set_size + pointers_in_set_size + ); } }