@@ -126,6 +126,9 @@ use core::ops::{self, Range, RangeBounds};
126126use core:: ptr:: { self , NonNull } ;
127127use core:: slice:: { self , SliceIndex } ;
128128
129+ #[ cfg( feature = "malloc_size_of" ) ]
130+ use malloc_size_of:: { MallocShallowSizeOf , MallocSizeOf , MallocSizeOfOps } ;
131+
129132#[ cfg( feature = "serde" ) ]
130133use serde:: {
131134 de:: { Deserialize , Deserializer , SeqAccess , Visitor } ,
@@ -1971,6 +1974,32 @@ where
19711974 }
19721975}
19731976
1977+ #[ cfg( feature = "malloc_size_of" ) ]
1978+ impl < A : Array > MallocShallowSizeOf for SmallVec < A > {
1979+ fn shallow_size_of ( & self , ops : & mut MallocSizeOfOps ) -> usize {
1980+ if self . spilled ( ) {
1981+ unsafe { ops. malloc_size_of ( self . as_ptr ( ) ) }
1982+ } else {
1983+ 0
1984+ }
1985+ }
1986+ }
1987+
1988+ #[ cfg( feature = "malloc_size_of" ) ]
1989+ impl < A > MallocSizeOf for SmallVec < A >
1990+ where
1991+ A : Array ,
1992+ A :: Item : MallocSizeOf ,
1993+ {
1994+ fn size_of ( & self , ops : & mut MallocSizeOfOps ) -> usize {
1995+ let mut n = self . shallow_size_of ( ops) ;
1996+ for elem in self . iter ( ) {
1997+ n += elem. size_of ( ops) ;
1998+ }
1999+ n
2000+ }
2001+ }
2002+
19742003#[ cfg( feature = "specialization" ) ]
19752004trait SpecFrom < A : Array , S > {
19762005 fn spec_from ( slice : S ) -> SmallVec < A > ;
0 commit comments