Skip to content

Commit bea1b46

Browse files
committed
---
yaml --- r: 97549 b: refs/heads/snap-stage3 c: 5da1663 h: refs/heads/master i: 97547: 9d6a138 v: v3
1 parent 8557deb commit bea1b46

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 0da105a8b7b6b1e0568e8ff20f6ff4b13cc7ecc2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 7613b15fdbbb9bf770a2c731f4135886b0ff3cf0
4+
refs/heads/snap-stage3: 5da166314f71804c2c54abcb1a91ccac7866908b
55
refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/gc.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ collector is task-local so `Gc<T>` is not sendable.
1818

1919
use kinds::Send;
2020
use clone::{Clone, DeepClone};
21+
use managed;
2122

2223
/// Immutable garbage-collected pointer type
2324
#[no_send]
24-
#[deriving(Clone)]
2525
pub struct Gc<T> {
2626
priv ptr: @T
2727
}
@@ -32,14 +32,26 @@ impl<T: 'static> Gc<T> {
3232
pub fn new(value: T) -> Gc<T> {
3333
Gc { ptr: @value }
3434
}
35-
}
3635

37-
impl<T: 'static> Gc<T> {
3836
/// Borrow the value contained in the garbage-collected box
3937
#[inline]
4038
pub fn borrow<'r>(&'r self) -> &'r T {
4139
&*self.ptr
4240
}
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+
}
4355
}
4456

4557
/// The `Send` bound restricts this to acyclic graphs where it is well-defined.
@@ -92,6 +104,16 @@ mod tests {
92104
assert_eq!(*y.borrow(), 5);
93105
}
94106

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+
95117
#[test]
96118
fn test_destructor() {
97119
let x = Gc::new(~5);

0 commit comments

Comments
 (0)