9
9
10
10
#![ allow( non_upper_case_globals) ]
11
11
12
- #[ cfg( feature = "heap_size " ) ]
12
+ #[ cfg( feature = "heapsize " ) ]
13
13
use heapsize:: HeapSizeOf ;
14
14
15
15
use serde:: { Deserialize , Deserializer , Serialize , Serializer } ;
@@ -46,7 +46,7 @@ struct StringCache {
46
46
buckets : [ Option < Box < StringCacheEntry > > ; NB_BUCKETS ] ,
47
47
}
48
48
49
- #[ cfg( feature = "heap_size " ) ]
49
+ #[ cfg( feature = "heapsize " ) ]
50
50
impl HeapSizeOf for StringCache {
51
51
fn heap_size_of_children ( & self ) -> usize {
52
52
self . buckets . iter ( ) . fold ( 0 , |size, bucket| size + bucket. heap_size_of_children ( ) )
@@ -58,24 +58,31 @@ lazy_static! {
58
58
}
59
59
60
60
/// A token that represents the heap used by the dynamic string cache.
61
- #[ cfg( feature = "heap_size " ) ]
61
+ #[ cfg( feature = "heapsize " ) ]
62
62
pub struct StringCacheHeap ;
63
63
64
- #[ cfg( feature = "heap_size " ) ]
64
+ #[ cfg( feature = "heapsize " ) ]
65
65
impl HeapSizeOf for StringCacheHeap {
66
66
fn heap_size_of_children ( & self ) -> usize {
67
67
STRING_CACHE . lock ( ) . unwrap ( ) . heap_size_of_children ( )
68
68
}
69
69
}
70
70
71
- #[ cfg_attr( feature = "heap_size" , derive( HeapSizeOf ) ) ]
72
71
struct StringCacheEntry {
73
72
next_in_bucket : Option < Box < StringCacheEntry > > ,
74
73
hash : u64 ,
75
74
ref_count : AtomicIsize ,
76
75
string : Box < str > ,
77
76
}
78
77
78
+ #[ cfg( feature = "heapsize" ) ]
79
+ impl HeapSizeOf for StringCacheEntry {
80
+ fn heap_size_of_children ( & self ) -> usize {
81
+ self . next_in_bucket . heap_size_of_children ( ) +
82
+ self . string . heap_size_of_children ( )
83
+ }
84
+ }
85
+
79
86
impl StringCacheEntry {
80
87
fn new ( next : Option < Box < StringCacheEntry > > , hash : u64 , string : String )
81
88
-> StringCacheEntry {
@@ -163,7 +170,6 @@ impl StringCache {
163
170
// NOTE: Deriving Eq here implies that a given string must always
164
171
// be interned the same way.
165
172
#[ cfg_attr( feature = "unstable" , unsafe_no_drop_flag) ] // See tests::atom_drop_is_idempotent
166
- #[ cfg_attr( feature = "heap_size" , derive( HeapSizeOf ) ) ]
167
173
#[ derive( Eq , Hash , PartialEq ) ]
168
174
pub struct Atom {
169
175
/// This field is public so that the `atom!()` macro can use it.
@@ -172,6 +178,9 @@ pub struct Atom {
172
178
pub unsafe_data : u64 ,
173
179
}
174
180
181
+ #[ cfg( feature = "heapsize" ) ]
182
+ known_heap_size ! ( 0 , Atom ) ;
183
+
175
184
pub struct BorrowedAtom < ' a > ( pub & ' a Atom ) ;
176
185
177
186
impl < ' a > ops:: Deref for BorrowedAtom < ' a > {
0 commit comments