mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
style: Allow to use ThinVec/nsTArray in the style crate
This allows to clean-up the previous patches by using a single ThinVec (which stores length / capacity along with the allocation). Differential Revision: https://phabricator.services.mozilla.com/D175029
This commit is contained in:
parent
a2df8f7ea5
commit
0709e13446
9 changed files with 110 additions and 48 deletions
|
@ -396,6 +396,28 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> MallocShallowSizeOf for thin_vec::ThinVec<T> {
|
||||
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||
if self.capacity() == 0 {
|
||||
// If it's the singleton we might not be a heap pointer.
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert_eq!(std::mem::size_of::<Self>(), std::mem::size_of::<*const ()>());
|
||||
unsafe { ops.malloc_size_of(*(self as *const Self as *const *const ())) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: MallocSizeOf> MallocSizeOf for thin_vec::ThinVec<T> {
|
||||
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||
let mut n = self.shallow_size_of(ops);
|
||||
for elem in self.iter() {
|
||||
n += elem.size_of(ops);
|
||||
}
|
||||
n
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! malloc_size_of_hash_set {
|
||||
($ty:ty) => {
|
||||
impl<T, S> MallocShallowSizeOf for $ty
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue