Skip to content

Commit 5f90f1c

Browse files
committed
auto merge of #6723 : osaut/rust/arc-remove-get, r=brson
* Remove clone and get functions from ARC. * Update the tests and bench.
2 parents 9a40c5c + ff28bb7 commit 5f90f1c

File tree

4 files changed

+24
-34
lines changed

4 files changed

+24
-34
lines changed

src/libextra/arc.rs

+11-21
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub impl<'self> Condvar<'self> {
107107
****************************************************************************/
108108

109109
/// An atomically reference counted wrapper for shared immutable state.
110-
struct ARC<T> { x: UnsafeAtomicRcBox<T> }
110+
pub struct ARC<T> { x: UnsafeAtomicRcBox<T> }
111111

112112
/// Create an atomically reference counted wrapper.
113113
pub fn ARC<T:Const + Owned>(data: T) -> ARC<T> {
@@ -118,29 +118,22 @@ pub fn ARC<T:Const + Owned>(data: T) -> ARC<T> {
118118
* Access the underlying data in an atomically reference counted
119119
* wrapper.
120120
*/
121-
pub fn get<'a, T:Const + Owned>(rc: &'a ARC<T>) -> &'a T {
122-
rc.get()
123-
}
124-
125-
impl<T:Const+Owned> ARC<T> {
126-
pub fn get<'a>(&'a self) -> &'a T {
121+
pub impl<T:Const+Owned> ARC<T> {
122+
fn get<'a>(&'a self) -> &'a T {
127123
unsafe { &*self.x.get_immut() }
128124
}
129125
}
126+
130127
/**
131128
* Duplicate an atomically reference counted wrapper.
132129
*
133130
* The resulting two `arc` objects will point to the same underlying data
134131
* object. However, one of the `arc` objects can be sent to another task,
135132
* allowing them to share the underlying data.
136133
*/
137-
pub fn clone<T:Const + Owned>(rc: &ARC<T>) -> ARC<T> {
138-
ARC { x: rc.x.clone() }
139-
}
140-
141134
impl<T:Const + Owned> Clone for ARC<T> {
142135
fn clone(&self) -> ARC<T> {
143-
clone(self)
136+
ARC { x: self.x.clone() }
144137
}
145138
}
146139

@@ -512,34 +505,31 @@ pub impl<'self, T:Const + Owned> RWReadMode<'self, T> {
512505
#[cfg(test)]
513506
mod tests {
514507
use core::prelude::*;
515-
508+
use core::cell::Cell;
516509
use arc::*;
517510
use arc;
518511

519-
use core::cell::Cell;
520-
use core::task;
521-
522512
#[test]
523513
fn manually_share_arc() {
524514
let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
525-
let arc_v = arc::ARC(v);
515+
let arc_v = ARC(v);
526516

527517
let (p, c) = comm::stream();
528518

529519
do task::spawn() || {
530520
let p = comm::PortSet::new();
531521
c.send(p.chan());
532522

533-
let arc_v = p.recv();
523+
let arc_v : ARC<~[int]> = p.recv();
534524

535-
let v = copy *arc::get::<~[int]>(&arc_v);
525+
let v = copy (*arc_v.get());
536526
assert_eq!(v[3], 4);
537527
};
538528

539529
let c = p.recv();
540-
c.send(arc::clone(&arc_v));
530+
c.send(arc_v.clone());
541531

542-
assert_eq!((*arc::get(&arc_v))[2], 3);
532+
assert_eq!(arc_v.get()[2], 3);
543533
assert_eq!(arc_v.get()[4], 5);
544534

545535
info!(arc_v);

src/test/bench/graph500-bfs.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// xfail-pretty
22

3-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
3+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
44
// file at the top-level directory of this distribution and at
55
// http://rust-lang.org/COPYRIGHT.
66
//
@@ -234,7 +234,7 @@ fn pbfs(graph: &arc::ARC<graph>, key: node_id) -> bfs_result {
234234
black(node_id)
235235
};
236236

237-
let graph_vec = arc::get(graph); // FIXME #3387 requires this temp
237+
let graph_vec = graph.get(); // FIXME #3387 requires this temp
238238
let mut colors = do vec::from_fn(graph_vec.len()) |i| {
239239
if i as node_id == key {
240240
gray(key)
@@ -266,13 +266,13 @@ fn pbfs(graph: &arc::ARC<graph>, key: node_id) -> bfs_result {
266266

267267
let color = arc::ARC(colors);
268268

269-
let color_vec = arc::get(&color); // FIXME #3387 requires this temp
269+
let color_vec = color.get(); // FIXME #3387 requires this temp
270270
colors = do par::mapi(*color_vec) {
271-
let colors = arc::clone(&color);
272-
let graph = arc::clone(graph);
271+
let colors = color.clone();
272+
let graph = graph.clone();
273273
let result: ~fn(x: uint, y: &color) -> color = |i, c| {
274-
let colors = arc::get(&colors);
275-
let graph = arc::get(&graph);
274+
let colors = colors.get();
275+
let graph = graph.get();
276276
match *c {
277277
white => {
278278
let i = i as node_id;

src/test/compile-fail/no-capture-arc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -18,11 +18,11 @@ fn main() {
1818
let arc_v = arc::ARC(v);
1919

2020
do task::spawn() {
21-
let v = *arc::get(&arc_v);
21+
let v = arc_v.get();
2222
assert_eq!(v[3], 4);
2323
};
2424

25-
assert_eq!((*arc::get(&arc_v))[2], 3);
25+
assert_eq!((arc_v.get())[2], 3);
2626

2727
info!(arc_v);
2828
}

src/test/compile-fail/no-reuse-move-arc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -16,11 +16,11 @@ fn main() {
1616
let arc_v = arc::ARC(v);
1717

1818
do task::spawn() { //~ NOTE `arc_v` moved into closure environment here
19-
let v = *arc::get(&arc_v);
19+
let v = arc_v.get();
2020
assert_eq!(v[3], 4);
2121
};
2222

23-
assert!((*arc::get(&arc_v))[2] == 3); //~ ERROR use of moved value: `arc_v`
23+
assert_eq!((arc_v.get())[2], 3); //~ ERROR use of moved value: `arc_v`
2424

2525
info!(arc_v);
2626
}

0 commit comments

Comments
 (0)