Skip to content

Commit ffb0949

Browse files
committed
---
yaml --- r: 107211 b: refs/heads/dist-snap c: 5da1663 h: refs/heads/master i: 107209: 56f3fe4 107207: 15506d2 v: v3
1 parent 1ab285a commit ffb0949

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
@@ -6,7 +6,7 @@ refs/heads/try: f64fdf524a434f0e5cd0bc91d09c144723f3c90d
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 7613b15fdbbb9bf770a2c731f4135886b0ff3cf0
9+
refs/heads/dist-snap: 5da166314f71804c2c54abcb1a91ccac7866908b
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/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)