aboutsummaryrefslogtreecommitdiffstats
path: root/components/util/mem.rs
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2015-03-31 08:32:11 +0530
committerManish Goregaokar <manishsmail@gmail.com>2015-06-03 07:12:00 +0530
commitf4bc92526a5b76d4d23267e9e5881f65eee264e8 (patch)
treedc80a4d33281b1f25693f71c5e9db2f84d68733d /components/util/mem.rs
parent05212b702dbafacd3d1d44e600139af8d7516308 (diff)
downloadservo-f4bc92526a5b76d4d23267e9e5881f65eee264e8.tar.gz
servo-f4bc92526a5b76d4d23267e9e5881f65eee264e8.zip
Add #[heapsize]/#[derive(HeapSizeOf)] plugin to auto-derive `HeapSizeOf` impls
(fixes #5914)
Diffstat (limited to 'components/util/mem.rs')
-rw-r--r--components/util/mem.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/components/util/mem.rs b/components/util/mem.rs
index cd1b9834e48..175863ddb9e 100644
--- a/components/util/mem.rs
+++ b/components/util/mem.rs
@@ -158,3 +158,31 @@ impl<T> Drop for LinkedList2<T> {
fn drop(&mut self) {}
}
+/// For use on types defined in external crates
+/// with known heap sizes
+#[macro_export]
+macro_rules! known_heap_size(
+ ($size:expr, $($ty:ident),+) => (
+ $(
+ impl $crate::mem::HeapSizeOf for $ty {
+ #[inline]
+ fn heap_size_of_children(&self) -> usize {
+ $size
+ }
+ }
+ )+
+ );
+ ($size: expr, $ty:ident<$($gen:ident),+>) => (
+ impl<$($gen),+> $crate::mem::HeapSizeOf for $ty<$($gen),+> {
+ #[inline]
+ fn heap_size_of_children(&self) -> usize {
+ $size
+ }
+ }
+ );
+);
+
+
+known_heap_size!(0, u8, u16, u32, u64, usize);
+known_heap_size!(0, i8, i16, i32, i64, isize);
+known_heap_size!(0, bool); \ No newline at end of file