File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 7613b15fdbbb9bf770a2c731f4135886b0ff3cf0
2
+ refs/heads/master: 5da166314f71804c2c54abcb1a91ccac7866908b
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
4
refs/heads/snap-stage3: b6400f998497c3958f40997a71756ead344a776d
5
5
refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
Original file line number Diff line number Diff line change @@ -18,10 +18,10 @@ collector is task-local so `Gc<T>` is not sendable.
18
18
19
19
use kinds:: Send ;
20
20
use clone:: { Clone , DeepClone } ;
21
+ use managed;
21
22
22
23
/// Immutable garbage-collected pointer type
23
24
#[ no_send]
24
- #[ deriving( Clone ) ]
25
25
pub struct Gc < T > {
26
26
priv ptr: @T
27
27
}
@@ -32,14 +32,26 @@ impl<T: 'static> Gc<T> {
32
32
pub fn new ( value : T ) -> Gc < T > {
33
33
Gc { ptr : @value }
34
34
}
35
- }
36
35
37
- impl < T : ' static > Gc < T > {
38
36
/// Borrow the value contained in the garbage-collected box
39
37
#[ inline]
40
38
pub fn borrow < ' r > ( & ' r self ) -> & ' r T {
41
39
& * self . ptr
42
40
}
41
+
42
+ /// Determine if two garbage-collected boxes point to the same object
43
+ #[ inline]
44
+ pub fn ptr_eq ( & self , other : & Gc < T > ) -> bool {
45
+ managed:: ptr_eq ( self . ptr , other. ptr )
46
+ }
47
+ }
48
+
49
+ impl < T > Clone for Gc < T > {
50
+ /// Clone the pointer only
51
+ #[ inline]
52
+ fn clone ( & self ) -> Gc < T > {
53
+ Gc { ptr : self . ptr }
54
+ }
43
55
}
44
56
45
57
/// The `Send` bound restricts this to acyclic graphs where it is well-defined.
@@ -92,6 +104,16 @@ mod tests {
92
104
assert_eq ! ( * y. borrow( ) , 5 ) ;
93
105
}
94
106
107
+ #[ test]
108
+ fn test_ptr_eq ( ) {
109
+ let x = Gc :: new ( 5 ) ;
110
+ let y = x. clone ( ) ;
111
+ let z = Gc :: new ( 7 ) ;
112
+ assert ! ( x. ptr_eq( & x) ) ;
113
+ assert ! ( x. ptr_eq( & y) ) ;
114
+ assert ! ( !x. ptr_eq( & z) ) ;
115
+ }
116
+
95
117
#[ test]
96
118
fn test_destructor ( ) {
97
119
let x = Gc :: new ( ~5 ) ;
You can’t perform that action at this time.
0 commit comments