@@ -163,6 +163,9 @@ use core::{fmt, mem, ptr, slice};
163163
164164use impl_details:: * ;
165165
166+ #[ cfg( feature = "malloc_size_of" ) ]
167+ use malloc_size_of:: { MallocShallowSizeOf , MallocSizeOf , MallocSizeOfOps } ;
168+
166169// modules: a simple way to cfg a whole bunch of impl details at once
167170
168171#[ cfg( not( feature = "gecko-ffi" ) ) ]
@@ -1873,6 +1876,33 @@ impl<'de, T: serde::Deserialize<'de>> serde::Deserialize<'de> for ThinVec<T> {
18731876 }
18741877}
18751878
1879+ #[ cfg( feature = "malloc_size_of" ) ]
1880+ impl < T > MallocShallowSizeOf for ThinVec < T > {
1881+ fn shallow_size_of ( & self , ops : & mut MallocSizeOfOps ) -> usize {
1882+ if self . capacity ( ) == 0 {
1883+ // If it's the singleton we might not be a heap pointer.
1884+ return 0 ;
1885+ }
1886+
1887+ assert_eq ! (
1888+ std:: mem:: size_of:: <Self >( ) ,
1889+ std:: mem:: size_of:: <* const ( ) >( )
1890+ ) ;
1891+ unsafe { ops. malloc_size_of ( * ( self as * const Self as * const * const ( ) ) ) }
1892+ }
1893+ }
1894+
1895+ #[ cfg( feature = "malloc_size_of" ) ]
1896+ impl < T : MallocSizeOf > MallocSizeOf for ThinVec < T > {
1897+ fn size_of ( & self , ops : & mut MallocSizeOfOps ) -> usize {
1898+ let mut n = self . shallow_size_of ( ops) ;
1899+ for elem in self . iter ( ) {
1900+ n += elem. size_of ( ops) ;
1901+ }
1902+ n
1903+ }
1904+ }
1905+
18761906macro_rules! array_impls {
18771907 ( $( $N: expr) * ) => { $(
18781908 impl <A , B > PartialEq <[ B ; $N] > for ThinVec <A > where A : PartialEq <B > {
0 commit comments