66//! to the heap for larger allocations. This can be a useful optimization for improving cache
77//! locality and reducing allocator traffic for workloads that fit within the inline buffer.
88
9+ #![ feature( specialization) ]
10+
11+ #[ cfg( feature="heapsizeof" ) ]
912extern crate heapsize;
1013
1114use std:: borrow:: { Borrow , BorrowMut } ;
@@ -14,11 +17,13 @@ use std::fmt;
1417use std:: hash:: { Hash , Hasher } ;
1518use std:: iter:: { IntoIterator , FromIterator } ;
1619use std:: mem;
17- use std:: os:: raw:: c_void;
1820use std:: ops;
1921use std:: ptr;
2022use std:: slice;
23+ #[ cfg( feature="heapsizeof" ) ]
24+ use std:: os:: raw:: c_void;
2125
26+ #[ cfg( feature="heapsizeof" ) ]
2227use heapsize:: { HeapSizeOf , heap_size_of} ;
2328use SmallVecData :: { Inline , Heap } ;
2429
@@ -510,6 +515,7 @@ impl<A: Array> SmallVec<A> where A::Item: Copy {
510515 }
511516}
512517
518+ #[ cfg( feature="heapsizeof" ) ]
513519impl < A : Array > HeapSizeOf for SmallVec < A > where A :: Item : HeapSizeOf {
514520 fn heap_size_of_children ( & self ) -> usize {
515521 match self . data {
@@ -853,9 +859,12 @@ impl_array!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 24, 32, 3
853859#[ cfg( test) ]
854860pub mod tests {
855861 use SmallVec ;
856- use heapsize:: HeapSizeOf ;
857862 use std:: borrow:: ToOwned ;
858863 use std:: iter:: FromIterator ;
864+
865+ #[ cfg( feature="heapsizeof" ) ]
866+ use heapsize:: HeapSizeOf ;
867+ #[ cfg( feature="heapsizeof" ) ]
859868 use std:: mem:: size_of;
860869
861870 // We heap allocate all these strings so that double frees will show up under valgrind.
@@ -1279,6 +1288,7 @@ pub mod tests {
12791288 assert_eq ! ( & SmallVec :: <[ u32 ; 2 ] >:: from_slice( & [ 1 , 2 , 3 ] [ ..] ) [ ..] , [ 1 , 2 , 3 ] ) ;
12801289 }
12811290
1291+ #[ cfg( feature="heapsizeof" ) ]
12821292 #[ test]
12831293 fn test_heap_size_of_children ( ) {
12841294 let mut vec = SmallVec :: < [ u32 ; 2 ] > :: new ( ) ;
0 commit comments