mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Add #[heapsize]/#[derive(HeapSizeOf)] plugin to auto-derive HeapSizeOf
impls
(fixes #5914)
This commit is contained in:
parent
05212b702d
commit
f4bc92526a
3 changed files with 87 additions and 2 deletions
|
@ -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);
|
Loading…
Add table
Add a link
Reference in a new issue