Skip to content

Commit 09b9e83

Browse files
committed
---
yaml --- r: 65048 b: refs/heads/master c: 6742f91 h: refs/heads/master v: v3
1 parent 669808e commit 09b9e83

File tree

16 files changed

+222
-29
lines changed

16 files changed

+222
-29
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: d953a5ce43ba2adecb50780c7debd3fea6248996
2+
refs/heads/master: 6742f91192da67324b33cf882383a283a2599f7b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,7 @@ struct TimeBomb {
19771977
19781978
impl Drop for TimeBomb {
19791979
fn finalize(&self) {
1980-
for self.explosivity.times {
1980+
for old_iter::repeat(self.explosivity) {
19811981
println("blam!");
19821982
}
19831983
}

trunk/src/libcore/old_iter.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,26 @@ pub fn position<A,IA:BaseIter<A>>(this: &IA, f: &fn(&A) -> bool)
238238
// iter interface, such as would provide "reach" in addition to "each". As is,
239239
// it would have to be implemented with foldr, which is too inefficient.
240240

241+
#[inline(always)]
242+
#[cfg(stage0)]
243+
pub fn repeat(times: uint, blk: &fn() -> bool) {
244+
let mut i = 0;
245+
while i < times {
246+
if !blk() { break }
247+
i += 1;
248+
}
249+
}
250+
#[inline(always)]
251+
#[cfg(not(stage0))]
252+
pub fn repeat(times: uint, blk: &fn() -> bool) -> bool {
253+
let mut i = 0;
254+
while i < times {
255+
if !blk() { return false; }
256+
i += 1;
257+
}
258+
return true;
259+
}
260+
241261
#[inline(always)]
242262
pub fn min<A:Copy + Ord,IA:BaseIter<A>>(this: &IA) -> A {
243263
match do foldl::<A,Option<A>,IA>(this, None) |a, b| {

trunk/src/libcore/prelude.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ pub use from_str::{FromStr};
5252
pub use to_bytes::IterBytes;
5353
pub use to_str::{ToStr, ToStrConsume};
5454
pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};
55+
pub use tuple::{Tuple2, Tuple3, Tuple4, Tuple5, Tuple6, Tuple7, Tuple8, Tuple9};
56+
pub use tuple::{Tuple10, Tuple11, Tuple12};
5557
pub use vec::{CopyableVector, ImmutableVector};
5658
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
5759
pub use vec::{OwnedVector, OwnedCopyableVector, MutableVector};

trunk/src/libcore/task/mod.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ fn test_spawn_unlinked_unsup_no_fail_down() { // grandchild sends on a port
619619
let ch = ch.clone();
620620
do spawn_unlinked {
621621
// Give middle task a chance to fail-but-not-kill-us.
622-
for 16.times { task::yield(); }
622+
for old_iter::repeat(16) { task::yield(); }
623623
ch.send(()); // If killed first, grandparent hangs.
624624
}
625625
fail!(); // Shouldn't kill either (grand)parent or (grand)child.
@@ -634,7 +634,7 @@ fn test_spawn_unlinked_unsup_no_fail_up() { // child unlinked fails
634634
fn test_spawn_unlinked_sup_no_fail_up() { // child unlinked fails
635635
do spawn_supervised { fail!(); }
636636
// Give child a chance to fail-but-not-kill-us.
637-
for 16.times { task::yield(); }
637+
for old_iter::repeat(16) { task::yield(); }
638638
}
639639
#[test] #[should_fail] #[ignore(cfg(windows))]
640640
fn test_spawn_unlinked_sup_fail_down() {
@@ -709,7 +709,7 @@ fn test_spawn_failure_propagate_grandchild() {
709709
loop { task::yield(); }
710710
}
711711
}
712-
for 16.times { task::yield(); }
712+
for old_iter::repeat(16) { task::yield(); }
713713
fail!();
714714
}
715715

@@ -721,7 +721,7 @@ fn test_spawn_failure_propagate_secondborn() {
721721
loop { task::yield(); }
722722
}
723723
}
724-
for 16.times { task::yield(); }
724+
for old_iter::repeat(16) { task::yield(); }
725725
fail!();
726726
}
727727

@@ -733,7 +733,7 @@ fn test_spawn_failure_propagate_nephew_or_niece() {
733733
loop { task::yield(); }
734734
}
735735
}
736-
for 16.times { task::yield(); }
736+
for old_iter::repeat(16) { task::yield(); }
737737
fail!();
738738
}
739739

@@ -745,7 +745,7 @@ fn test_spawn_linked_sup_propagate_sibling() {
745745
loop { task::yield(); }
746746
}
747747
}
748-
for 16.times { task::yield(); }
748+
for old_iter::repeat(16) { task::yield(); }
749749
fail!();
750750
}
751751

@@ -904,7 +904,8 @@ fn test_spawn_sched_blocking() {
904904

905905
// Testing that a task in one scheduler can block in foreign code
906906
// without affecting other schedulers
907-
for 20u.times {
907+
for old_iter::repeat(20u) {
908+
908909
let (start_po, start_ch) = stream();
909910
let (fin_po, fin_ch) = stream();
910911

@@ -1023,7 +1024,7 @@ fn test_unkillable() {
10231024

10241025
// We want to do this after failing
10251026
do spawn_unlinked {
1026-
for 10.times { yield() }
1027+
for old_iter::repeat(10) { yield() }
10271028
ch.send(());
10281029
}
10291030

@@ -1058,7 +1059,7 @@ fn test_unkillable_nested() {
10581059

10591060
// We want to do this after failing
10601061
do spawn_unlinked || {
1061-
for 10.times { yield() }
1062+
for old_iter::repeat(10) { yield() }
10621063
ch.send(());
10631064
}
10641065

trunk/src/libcore/tuple.rs

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,154 @@ impl<A:Ord,B:Ord,C:Ord> Ord for (A, B, C) {
246246
fn gt(&self, other: &(A, B, C)) -> bool { (*other).lt(&(*self)) }
247247
}
248248

249+
// Tuple element accessor traits
250+
251+
macro_rules! n_tuple(
252+
($name:ident: $($method:ident : $T:ident),+) => (
253+
pub trait $name<$($T),+> {
254+
$(fn $method(&self) -> $T;)+
255+
}
256+
)
257+
)
258+
259+
n_tuple!(Tuple2: _0:A, _1:B)
260+
n_tuple!(Tuple3: _0:A, _1:B, _2:C)
261+
n_tuple!(Tuple4: _0:A, _1:B, _2:C, _3:D)
262+
n_tuple!(Tuple5: _0:A, _1:B, _2:C, _3:D, _4:E)
263+
n_tuple!(Tuple6: _0:A, _1:B, _2:C, _3:D, _4:E, _5:F)
264+
n_tuple!(Tuple7: _0:A, _1:B, _2:C, _3:D, _4:E, _5:F, _6:G)
265+
n_tuple!(Tuple8: _0:A, _1:B, _2:C, _3:D, _4:E, _5:F, _6:G, _7:H)
266+
n_tuple!(Tuple9: _0:A, _1:B, _2:C, _3:D, _4:E, _5:F, _6:G, _7:H, _8:I)
267+
n_tuple!(Tuple10: _0:A, _1:B, _2:C, _3:D, _4:E, _5:F, _6:G, _7:H, _8:I, _9:J)
268+
n_tuple!(Tuple11: _0:A, _1:B, _2:C, _3:D, _4:E, _5:F, _6:G, _7:H, _8:I, _9:J, _10:K)
269+
n_tuple!(Tuple12: _0:A, _1:B, _2:C, _3:D, _4:E, _5:F, _6:G, _7:H, _8:I, _9:J, _10:K, _11:L)
270+
271+
// Tuple element accessor trait implementations
272+
273+
macro_rules! impl_n_tuple(
274+
($name:ident: $($method:ident -> $T:ident { $accessor:pat => $t:expr })+) => (
275+
impl<$($T:Copy),+> $name<$($T),+> for ($($T),+) {
276+
$(
277+
fn $method(&self) -> $T {
278+
match *self {
279+
$accessor => $t
280+
}
281+
}
282+
)+
283+
}
284+
)
285+
)
286+
287+
impl_n_tuple!(Tuple2:
288+
_0 -> A { (a,_) => a }
289+
_1 -> B { (_,b) => b }
290+
)
291+
292+
impl_n_tuple!(Tuple3:
293+
_0 -> A { (a,_,_) => a }
294+
_1 -> B { (_,b,_) => b }
295+
_2 -> C { (_,_,c) => c }
296+
)
297+
298+
impl_n_tuple!(Tuple4:
299+
_0 -> A { (a,_,_,_) => a }
300+
_1 -> B { (_,b,_,_) => b }
301+
_2 -> C { (_,_,c,_) => c }
302+
_3 -> D { (_,_,_,d) => d }
303+
)
304+
305+
impl_n_tuple!(Tuple5:
306+
_0 -> A { (a,_,_,_,_) => a }
307+
_1 -> B { (_,b,_,_,_) => b }
308+
_2 -> C { (_,_,c,_,_) => c }
309+
_3 -> D { (_,_,_,d,_) => d }
310+
_4 -> E { (_,_,_,_,e) => e }
311+
)
312+
313+
impl_n_tuple!(Tuple6:
314+
_0 -> A { (a,_,_,_,_,_) => a }
315+
_1 -> B { (_,b,_,_,_,_) => b }
316+
_2 -> C { (_,_,c,_,_,_) => c }
317+
_3 -> D { (_,_,_,d,_,_) => d }
318+
_4 -> E { (_,_,_,_,e,_) => e }
319+
_5 -> F { (_,_,_,_,_,f) => f }
320+
)
321+
322+
impl_n_tuple!(Tuple7:
323+
_0 -> A { (a,_,_,_,_,_,_) => a }
324+
_1 -> B { (_,b,_,_,_,_,_) => b }
325+
_2 -> C { (_,_,c,_,_,_,_) => c }
326+
_3 -> D { (_,_,_,d,_,_,_) => d }
327+
_4 -> E { (_,_,_,_,e,_,_) => e }
328+
_5 -> F { (_,_,_,_,_,f,_) => f }
329+
_6 -> G { (_,_,_,_,_,_,g) => g }
330+
)
331+
332+
impl_n_tuple!(Tuple8:
333+
_0 -> A { (a,_,_,_,_,_,_,_) => a }
334+
_1 -> B { (_,b,_,_,_,_,_,_) => b }
335+
_2 -> C { (_,_,c,_,_,_,_,_) => c }
336+
_3 -> D { (_,_,_,d,_,_,_,_) => d }
337+
_4 -> E { (_,_,_,_,e,_,_,_) => e }
338+
_5 -> F { (_,_,_,_,_,f,_,_) => f }
339+
_6 -> G { (_,_,_,_,_,_,g,_) => g }
340+
_7 -> H { (_,_,_,_,_,_,_,h) => h }
341+
)
342+
343+
impl_n_tuple!(Tuple9:
344+
_0 -> A { (a,_,_,_,_,_,_,_,_) => a }
345+
_1 -> B { (_,b,_,_,_,_,_,_,_) => b }
346+
_2 -> C { (_,_,c,_,_,_,_,_,_) => c }
347+
_3 -> D { (_,_,_,d,_,_,_,_,_) => d }
348+
_4 -> E { (_,_,_,_,e,_,_,_,_) => e }
349+
_5 -> F { (_,_,_,_,_,f,_,_,_) => f }
350+
_6 -> G { (_,_,_,_,_,_,g,_,_) => g }
351+
_7 -> H { (_,_,_,_,_,_,_,h,_) => h }
352+
_8 -> I { (_,_,_,_,_,_,_,_,i) => i }
353+
)
354+
355+
impl_n_tuple!(Tuple10:
356+
_0 -> A { (a,_,_,_,_,_,_,_,_,_) => a }
357+
_1 -> B { (_,b,_,_,_,_,_,_,_,_) => b }
358+
_2 -> C { (_,_,c,_,_,_,_,_,_,_) => c }
359+
_3 -> D { (_,_,_,d,_,_,_,_,_,_) => d }
360+
_4 -> E { (_,_,_,_,e,_,_,_,_,_) => e }
361+
_5 -> F { (_,_,_,_,_,f,_,_,_,_) => f }
362+
_6 -> G { (_,_,_,_,_,_,g,_,_,_) => g }
363+
_7 -> H { (_,_,_,_,_,_,_,h,_,_) => h }
364+
_8 -> I { (_,_,_,_,_,_,_,_,i,_) => i }
365+
_9 -> J { (_,_,_,_,_,_,_,_,_,j) => j }
366+
)
367+
368+
impl_n_tuple!(Tuple11:
369+
_0 -> A { (a,_,_,_,_,_,_,_,_,_,_) => a }
370+
_1 -> B { (_,b,_,_,_,_,_,_,_,_,_) => b }
371+
_2 -> C { (_,_,c,_,_,_,_,_,_,_,_) => c }
372+
_3 -> D { (_,_,_,d,_,_,_,_,_,_,_) => d }
373+
_4 -> E { (_,_,_,_,e,_,_,_,_,_,_) => e }
374+
_5 -> F { (_,_,_,_,_,f,_,_,_,_,_) => f }
375+
_6 -> G { (_,_,_,_,_,_,g,_,_,_,_) => g }
376+
_7 -> H { (_,_,_,_,_,_,_,h,_,_,_) => h }
377+
_8 -> I { (_,_,_,_,_,_,_,_,i,_,_) => i }
378+
_9 -> J { (_,_,_,_,_,_,_,_,_,j,_) => j }
379+
_10 -> K { (_,_,_,_,_,_,_,_,_,_,k) => k }
380+
)
381+
382+
impl_n_tuple!(Tuple12:
383+
_0 -> A { (a,_,_,_,_,_,_,_,_,_,_,_) => a }
384+
_1 -> B { (_,b,_,_,_,_,_,_,_,_,_,_) => b }
385+
_2 -> C { (_,_,c,_,_,_,_,_,_,_,_,_) => c }
386+
_3 -> D { (_,_,_,d,_,_,_,_,_,_,_,_) => d }
387+
_4 -> E { (_,_,_,_,e,_,_,_,_,_,_,_) => e }
388+
_5 -> F { (_,_,_,_,_,f,_,_,_,_,_,_) => f }
389+
_6 -> G { (_,_,_,_,_,_,g,_,_,_,_,_) => g }
390+
_7 -> H { (_,_,_,_,_,_,_,h,_,_,_,_) => h }
391+
_8 -> I { (_,_,_,_,_,_,_,_,i,_,_,_) => i }
392+
_9 -> J { (_,_,_,_,_,_,_,_,_,j,_,_) => j }
393+
_10 -> K { (_,_,_,_,_,_,_,_,_,_,k,_) => k }
394+
_11 -> L { (_,_,_,_,_,_,_,_,_,_,_,l) => l }
395+
)
396+
249397
#[test]
250398
fn test_tuple_ref() {
251399
let x = (~"foo", ~"bar");
@@ -268,3 +416,20 @@ fn test_clone() {
268416
assert!(a.first() == b.first());
269417
assert!(a.second() == b.second());
270418
}
419+
420+
#[test]
421+
fn test_n_tuple() {
422+
let t = (0u8, 1u16, 2u32, 3u64, 4u, 5i8, 6i16, 7i32, 8i64, 9i, 10f32, 11f64);
423+
assert_eq!(t._0(), 0u8);
424+
assert_eq!(t._1(), 1u16);
425+
assert_eq!(t._2(), 2u32);
426+
assert_eq!(t._3(), 3u64);
427+
assert_eq!(t._4(), 4u);
428+
assert_eq!(t._5(), 5i8);
429+
assert_eq!(t._6(), 6i16);
430+
assert_eq!(t._7(), 7i32);
431+
assert_eq!(t._8(), 8i64);
432+
assert_eq!(t._9(), 9i);
433+
assert_eq!(t._10(), 10f32);
434+
assert_eq!(t._11(), 11f64);
435+
}

trunk/src/librustdoc/markdown_pass.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ mod test {
629629
let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc);
630630
write_markdown(doc, writer_factory);
631631
// We expect two pages to have been written
632-
for 2.times {
632+
for old_iter::repeat(2) {
633633
po.recv();
634634
}
635635
}
@@ -641,7 +641,7 @@ mod test {
641641
~"#[link(name = \"core\")]; mod a { }");
642642
let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc);
643643
write_markdown(doc, writer_factory);
644-
for 2.times {
644+
for old_iter::repeat(2) {
645645
let (page, markdown) = po.recv();
646646
match page {
647647
doc::CratePage(_) => {

trunk/src/libstd/base64.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
//! Base64 binary-to-text encoding
1212
13+
use core::old_iter;
14+
use core::str;
15+
use core::vec;
16+
1317
pub trait ToBase64 {
1418
fn to_base64(&self) -> ~str;
1519
}
@@ -148,7 +152,7 @@ impl FromBase64 for ~[u8] {
148152
while i < len {
149153
let mut n = 0u;
150154

151-
for 4u.times {
155+
for old_iter::repeat(4u) {
152156
let ch = self[i] as char;
153157
n <<= 6u;
154158

0 commit comments

Comments
 (0)