diff --git a/Cargo.toml b/Cargo.toml index 515af8e..5e7b909 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "heapsize" -version = "0.3.1" +version = "0.3.2" authors = [ "The Servo Project Developers" ] description = "Infrastructure for measuring the total runtime size of an object on the heap" license = "MPL-2.0" diff --git a/src/lib.rs b/src/lib.rs index fd33a4a..e92aea7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ use std::borrow::Cow; use std::cell::{Cell, RefCell}; -use std::collections::{BTreeMap, HashMap, LinkedList}; +use std::collections::{BTreeMap, HashMap, LinkedList, VecDeque}; #[cfg(feature = "unstable")] use std::hash::BuildHasher; use std::hash::Hash; @@ -160,10 +160,18 @@ impl HeapSizeOf for Cell { impl HeapSizeOf for Vec { fn heap_size_of_children(&self) -> usize { - unsafe { - heap_size_of(self.as_ptr() as *const c_void) - + self.iter().fold(0, |n, elem| n + elem.heap_size_of_children()) - } + self.iter().fold( + unsafe { heap_size_of(self.as_ptr() as *const c_void) }, + |n, elem| n + elem.heap_size_of_children()) + } +} + +impl HeapSizeOf for VecDeque { + fn heap_size_of_children(&self) -> usize { + self.iter().fold( + // FIXME: get the buffer pointer for heap_size_of(), capacity() is a lower bound: + self.capacity() * size_of::(), + |n, elem| n + elem.heap_size_of_children()) } }