Skip to content

Commit c8db9e2

Browse files
committed
auto merge of #8905 : sstewartgallus/rust/cleanup_tests, r=bblum
In this commit I: - removed unneeded heap allocations - added extra whitespace to crowded expressions - and removed unneeded syntax Also, CC @bblum although this change is fairly unobjectionable.
2 parents bb35e23 + e2f2a60 commit c8db9e2

File tree

2 files changed

+153
-154
lines changed

2 files changed

+153
-154
lines changed

src/libextra/arc.rs

+49-49
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,10 @@ mod tests {
572572
573573
let (p, c) = comm::stream();
574574
575-
do task::spawn() || {
576-
let arc_v : Arc<~[int]> = p.recv();
575+
do task::spawn {
576+
let arc_v: Arc<~[int]> = p.recv();
577577
578-
let v = (*arc_v.get()).clone();
578+
let v = arc_v.get().clone();
579579
assert_eq!(v[3], 4);
580580
};
581581
@@ -590,11 +590,11 @@ mod tests {
590590
#[test]
591591
fn test_mutex_arc_condvar() {
592592
unsafe {
593-
let arc = ~MutexArc::new(false);
594-
let arc2 = ~arc.clone();
595-
let (p,c) = comm::oneshot();
596-
let (c,p) = (Cell::new(c), Cell::new(p));
597-
do task::spawn || {
593+
let arc = MutexArc::new(false);
594+
let arc2 = arc.clone();
595+
let (p, c) = comm::oneshot();
596+
let (c, p) = (Cell::new(c), Cell::new(p));
597+
do task::spawn {
598598
// wait until parent gets in
599599
p.take().recv();
600600
do arc2.access_cond |state, cond| {
@@ -615,11 +615,11 @@ mod tests {
615615
#[test] #[should_fail]
616616
fn test_arc_condvar_poison() {
617617
unsafe {
618-
let arc = ~MutexArc::new(1);
619-
let arc2 = ~arc.clone();
618+
let arc = MutexArc::new(1);
619+
let arc2 = arc.clone();
620620
let (p, c) = comm::stream();
621621
622-
do task::spawn_unlinked || {
622+
do task::spawn_unlinked {
623623
let _ = p.recv();
624624
do arc2.access_cond |one, cond| {
625625
cond.signal();
@@ -639,9 +639,9 @@ mod tests {
639639
#[test] #[should_fail]
640640
fn test_mutex_arc_poison() {
641641
unsafe {
642-
let arc = ~MutexArc::new(1);
643-
let arc2 = ~arc.clone();
644-
do task::try || {
642+
let arc = MutexArc::new(1);
643+
let arc2 = arc.clone();
644+
do task::try {
645645
do arc2.access |one| {
646646
assert_eq!(*one, 2);
647647
}
@@ -654,7 +654,7 @@ mod tests {
654654
#[test] #[should_fail]
655655
pub fn test_mutex_arc_unwrap_poison() {
656656
let arc = MutexArc::new(1);
657-
let arc2 = ~(&arc).clone();
657+
let arc2 = arc.clone();
658658
let (p, c) = comm::stream();
659659
do task::spawn {
660660
unsafe {
@@ -670,9 +670,9 @@ mod tests {
670670
}
671671
#[test] #[should_fail]
672672
fn test_rw_arc_poison_wr() {
673-
let arc = ~RWArc::new(1);
674-
let arc2 = (*arc).clone();
675-
do task::try || {
673+
let arc = RWArc::new(1);
674+
let arc2 = arc.clone();
675+
do task::try {
676676
do arc2.write |one| {
677677
assert_eq!(*one, 2);
678678
}
@@ -683,9 +683,9 @@ mod tests {
683683
}
684684
#[test] #[should_fail]
685685
fn test_rw_arc_poison_ww() {
686-
let arc = ~RWArc::new(1);
687-
let arc2 = (*arc).clone();
688-
do task::try || {
686+
let arc = RWArc::new(1);
687+
let arc2 = arc.clone();
688+
do task::try {
689689
do arc2.write |one| {
690690
assert_eq!(*one, 2);
691691
}
@@ -696,9 +696,9 @@ mod tests {
696696
}
697697
#[test] #[should_fail]
698698
fn test_rw_arc_poison_dw() {
699-
let arc = ~RWArc::new(1);
700-
let arc2 = (*arc).clone();
701-
do task::try || {
699+
let arc = RWArc::new(1);
700+
let arc2 = arc.clone();
701+
do task::try {
702702
do arc2.write_downgrade |mut write_mode| {
703703
do write_mode.write |one| {
704704
assert_eq!(*one, 2);
@@ -711,9 +711,9 @@ mod tests {
711711
}
712712
#[test]
713713
fn test_rw_arc_no_poison_rr() {
714-
let arc = ~RWArc::new(1);
715-
let arc2 = (*arc).clone();
716-
do task::try || {
714+
let arc = RWArc::new(1);
715+
let arc2 = arc.clone();
716+
do task::try {
717717
do arc2.read |one| {
718718
assert_eq!(*one, 2);
719719
}
@@ -724,9 +724,9 @@ mod tests {
724724
}
725725
#[test]
726726
fn test_rw_arc_no_poison_rw() {
727-
let arc = ~RWArc::new(1);
728-
let arc2 = (*arc).clone();
729-
do task::try || {
727+
let arc = RWArc::new(1);
728+
let arc2 = arc.clone();
729+
do task::try {
730730
do arc2.read |one| {
731731
assert_eq!(*one, 2);
732732
}
@@ -737,12 +737,12 @@ mod tests {
737737
}
738738
#[test]
739739
fn test_rw_arc_no_poison_dr() {
740-
let arc = ~RWArc::new(1);
741-
let arc2 = (*arc).clone();
742-
do task::try || {
740+
let arc = RWArc::new(1);
741+
let arc2 = arc.clone();
742+
do task::try {
743743
do arc2.write_downgrade |write_mode| {
744744
let read_mode = arc2.downgrade(write_mode);
745-
do (&read_mode).read |one| {
745+
do read_mode.read |one| {
746746
assert_eq!(*one, 2);
747747
}
748748
}
@@ -753,11 +753,11 @@ mod tests {
753753
}
754754
#[test]
755755
fn test_rw_arc() {
756-
let arc = ~RWArc::new(0);
757-
let arc2 = (*arc).clone();
758-
let (p,c) = comm::stream();
756+
let arc = RWArc::new(0);
757+
let arc2 = arc.clone();
758+
let (p, c) = comm::stream();
759759
760-
do task::spawn || {
760+
do task::spawn {
761761
do arc2.write |num| {
762762
do 10.times {
763763
let tmp = *num;
@@ -772,7 +772,7 @@ mod tests {
772772
// Readers try to catch the writer in the act
773773
let mut children = ~[];
774774
do 5.times {
775-
let arc3 = (*arc).clone();
775+
let arc3 = arc.clone();
776776
let mut builder = task::task();
777777
builder.future_result(|r| children.push(r));
778778
do builder.spawn {
@@ -801,15 +801,15 @@ mod tests {
801801
// (4) tells writer and all other readers to contend as it downgrades.
802802
// (5) Writer attempts to set state back to 42, while downgraded task
803803
// and all reader tasks assert that it's 31337.
804-
let arc = ~RWArc::new(0);
804+
let arc = RWArc::new(0);
805805
806806
// Reader tasks
807807
let mut reader_convos = ~[];
808808
do 10.times {
809-
let ((rp1,rc1),(rp2,rc2)) = (comm::stream(),comm::stream());
809+
let ((rp1, rc1), (rp2, rc2)) = (comm::stream(), comm::stream());
810810
reader_convos.push((rc1, rp2));
811-
let arcn = (*arc).clone();
812-
do task::spawn || {
811+
let arcn = arc.clone();
812+
do task::spawn {
813813
rp1.recv(); // wait for downgrader to give go-ahead
814814
do arcn.read |state| {
815815
assert_eq!(*state, 31337);
@@ -819,8 +819,8 @@ mod tests {
819819
}
820820
821821
// Writer task
822-
let arc2 = (*arc).clone();
823-
let ((wp1,wc1),(wp2,wc2)) = (comm::stream(),comm::stream());
822+
let arc2 = arc.clone();
823+
let ((wp1, wc1), (wp2, wc2)) = (comm::stream(), comm::stream());
824824
do task::spawn || {
825825
wp1.recv();
826826
do arc2.write_cond |state, cond| {
@@ -853,7 +853,7 @@ mod tests {
853853
}
854854
}
855855
let read_mode = arc.downgrade(write_mode);
856-
do (&read_mode).read |state| {
856+
do read_mode.read |state| {
857857
// complete handshake with other readers
858858
for &(_, ref rp) in reader_convos.iter() {
859859
rp.recv()
@@ -876,11 +876,11 @@ mod tests {
876876
// line in RWLock::write_cond() that looks like:
877877
// "blk(&Condvar { order: opt_lock, ..*cond })"
878878
// with just "blk(cond)".
879-
let x = ~RWArc::new(true);
879+
let x = RWArc::new(true);
880880
let (wp, wc) = comm::stream();
881881
882882
// writer task
883-
let xw = (*x).clone();
883+
let xw = x.clone();
884884
do task::spawn {
885885
do xw.write_cond |state, c| {
886886
wc.send(()); // tell downgrader it's ok to go
@@ -901,7 +901,7 @@ mod tests {
901901
c.signal();
902902
}
903903
// make a reader task to trigger the "reader cloud lock" handoff
904-
let xr = (*x).clone();
904+
let xr = x.clone();
905905
let (rp, rc) = comm::stream();
906906
do task::spawn {
907907
rc.send(());

0 commit comments

Comments
 (0)