File tree 3 files changed +42
-1
lines changed
3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ pub(crate) struct Metadata {
20
20
}
21
21
22
22
#[ derive( Clone ) ]
23
- pub ( crate ) struct Item ( ThinArc < HeaderWithLength < Metadata > , u8 > ) ;
23
+ pub ( crate ) struct Item ( pub ThinArc < HeaderWithLength < Metadata > , u8 > ) ;
24
24
25
25
impl Deref for Item {
26
26
type Target = <ThinArc < HeaderWithLength < Metadata > , u8 > as Deref >:: Target ;
Original file line number Diff line number Diff line change @@ -273,6 +273,20 @@ impl Atom {
273
273
}
274
274
}
275
275
276
+ #[ cfg( test) ]
277
+ impl Atom {
278
+ pub ( crate ) fn ref_count ( & self ) -> usize {
279
+ match self . tag ( ) {
280
+ DYNAMIC_TAG => {
281
+ let ptr = unsafe { crate :: dynamic:: deref_from ( self . unsafe_data ) } ;
282
+
283
+ triomphe:: ThinArc :: strong_count ( & ptr. 0 )
284
+ }
285
+ _ => 1 ,
286
+ }
287
+ }
288
+ }
289
+
276
290
impl PartialEq for Atom {
277
291
#[ inline( never) ]
278
292
fn eq ( & self , other : & Self ) -> bool {
Original file line number Diff line number Diff line change @@ -55,3 +55,30 @@ fn store_multiple() {
55
55
assert_eq ! ( a1. get_hash( ) , a2. get_hash( ) , "Same string should be equal" ) ;
56
56
assert_eq ! ( a1, a2, "Same string should be equal" ) ;
57
57
}
58
+
59
+ #[ test]
60
+ fn store_ref_count ( ) {
61
+ let ( store, atoms) = store_with_atoms ( vec ! [ "Hello, world!!!!" ] ) ;
62
+
63
+ assert_eq ! ( atoms[ 0 ] . ref_count( ) , 2 ) ;
64
+ drop ( store) ;
65
+ assert_eq ! ( atoms[ 0 ] . ref_count( ) , 1 ) ;
66
+ }
67
+
68
+ #[ test]
69
+ fn store_ref_count_dynamic ( ) {
70
+ let ( store, atoms) = store_with_atoms ( vec ! [ "Hello, world!!!!" ] ) ;
71
+
72
+ let a1 = atoms[ 0 ] . clone ( ) ;
73
+ let a2 = atoms[ 0 ] . clone ( ) ;
74
+
75
+ assert_eq ! ( atoms[ 0 ] . ref_count( ) , 4 ) ;
76
+ drop ( store) ;
77
+ assert_eq ! ( atoms[ 0 ] . ref_count( ) , 3 ) ;
78
+
79
+ drop ( a1) ;
80
+ assert_eq ! ( atoms[ 0 ] . ref_count( ) , 2 ) ;
81
+
82
+ drop ( a2) ;
83
+ assert_eq ! ( atoms[ 0 ] . ref_count( ) , 1 ) ;
84
+ }
You can’t perform that action at this time.
0 commit comments