Stop using the '<->' operator

This commit is contained in:
Alex Crichton 2013-05-06 00:42:54 -04:00
parent 7d22437ecd
commit 998fececd6
29 changed files with 214 additions and 296 deletions

View file

@ -8,14 +8,16 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::util;
struct Ints {sum: ~int, values: ~[int]}
fn add_int(x: &mut Ints, v: int) {
*x.sum += v;
let mut values = ~[];
x.values <-> values;
util::swap(&mut values, &mut x.values);
values.push(v);
x.values <-> values;
util::swap(&mut values, &mut x.values);
}
fn iter_ints(x: &Ints, f: &fn(x: &int) -> bool) -> bool {

View file

@ -10,8 +10,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::util;
// tjc: I don't know why
pub mod pipes {
use core::util;
use core::cast::{forget, transmute};
pub struct Stuff<T> {
@ -104,8 +107,7 @@ pub mod pipes {
match old_state {
empty | blocked => { task::yield(); }
full => {
let mut payload = None;
payload <-> (*p).payload;
let payload = util::replace(&mut p.payload, None);
return Some(payload.unwrap())
}
terminated => {
@ -159,10 +161,9 @@ pub mod pipes {
fn finalize(&self) {
unsafe {
if self.p != None {
let mut p = None;
let self_p: &mut Option<*packet<T>> =
cast::transmute(&self.p);
p <-> *self_p;
let p = util::replace(self_p, None);
sender_terminate(p.unwrap())
}
}
@ -171,9 +172,7 @@ pub mod pipes {
pub impl<T:Owned> send_packet<T> {
fn unwrap(&mut self) -> *packet<T> {
let mut p = None;
p <-> self.p;
p.unwrap()
util::replace(&mut self.p, None).unwrap()
}
}
@ -192,10 +191,9 @@ pub mod pipes {
fn finalize(&self) {
unsafe {
if self.p != None {
let mut p = None;
let self_p: &mut Option<*packet<T>> =
cast::transmute(&self.p);
p <-> *self_p;
let p = util::replace(self_p, None);
receiver_terminate(p.unwrap())
}
}
@ -204,9 +202,7 @@ pub mod pipes {
pub impl<T:Owned> recv_packet<T> {
fn unwrap(&mut self) -> *packet<T> {
let mut p = None;
p <-> self.p;
p.unwrap()
util::replace(&mut self.p, None).unwrap()
}
}
@ -225,6 +221,7 @@ pub mod pipes {
pub mod pingpong {
use core::cast;
use core::ptr;
use core::util;
pub struct ping(::pipes::send_packet<pong>);
pub struct pong(::pipes::send_packet<ping>);

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::util;
pub fn main() {
let mut x = 4;
@ -24,6 +26,6 @@ pub fn main() {
}
}
let mut y = 4;
y <-> x;
util::swap(&mut y, &mut x);
}
}

View file

@ -8,7 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::util;
pub fn main() {
let mut x = 3; let mut y = 7;
x <-> y; assert!((x == 7)); assert!((y == 3));
util::swap(&mut x, &mut y);
assert!((x == 7)); assert!((y == 3));
}

View file

@ -8,15 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn swap<T>(v: &mut [T], i: int, j: int) { v[i] <-> v[j]; }
use core::util;
pub fn main() {
let mut a: ~[int] = ~[0, 1, 2, 3, 4, 5, 6];
swap(a, 2, 4);
vec::swap(a, 2, 4);
assert!((a[2] == 4));
assert!((a[4] == 2));
let mut n = 42;
n <-> a[0];
util::swap(&mut n, &mut a[0]);
assert!((a[0] == 42));
assert!((n == 0));
}

View file

@ -10,6 +10,8 @@
// Issue #5041 - avoid overlapping memcpy when src and dest of a swap are the same
use core::util;
pub fn main() {
let mut test = TestDescAndFn {
desc: TestDesc {
@ -22,7 +24,10 @@ pub fn main() {
}
fn do_swap(test: &mut TestDescAndFn) {
*test <-> *test;
unsafe {
util::swap_ptr(ptr::to_mut_unsafe_ptr(test),
ptr::to_mut_unsafe_ptr(test));
}
}
pub enum TestName {

View file

@ -8,10 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::util;
pub fn main() {
let mut i = ~100;
let mut j = ~200;
i <-> j;
util::swap(&mut i, &mut j);
assert!(i == ~200);
assert!(j == ~100);
}

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::util;
// Just a grab bag of stuff that you wouldn't want to actually write.
fn strange() -> bool { let _x: bool = return true; }
@ -52,7 +54,7 @@ fn notsure() {
let mut _y = (_x = 0) == (_x = 0);
let mut _z = (_x = 0) < (_x = 0);
let _a = (_x += 0) == (_x = 0);
let _b = (_y <-> _z) == (_y <-> _z);
let _b = util::swap(&mut _y, &mut _z) == util::swap(&mut _y, &mut _z);
}
fn canttouchthis() -> uint {