Skip to content

Commit eb38511

Browse files
committed
---
yaml --- r: 56893 b: refs/heads/try c: 1ab1354 h: refs/heads/master i: 56891: b2e3f7c v: v3
1 parent c057ac2 commit eb38511

34 files changed

+461
-1189
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: c081ffbd1e845687202a975ea2e698b623e5722f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 79a2b2eafc3c766cecec8a5f76317693bae9ed17
5-
refs/heads/try: 6994340ca0ff75fd9fcef7defed8c5bfd7cab448
5+
refs/heads/try: 1ab13549372ca12406ed948f1cdbcd5fd9da2e0f
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libcore/core.rc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub use vec::{OwnedVector, OwnedCopyableVector};
9999
pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
100100
pub use iter::{CopyableOrderedIter, CopyableNonstrictIter, Times};
101101

102-
pub use num::NumCast;
102+
pub use num::{Num, NumCast};
103103
pub use ptr::Ptr;
104104
pub use to_str::ToStr;
105105
pub use clone::Clone;
@@ -176,6 +176,7 @@ pub mod from_str;
176176
#[path = "num/num.rs"]
177177
pub mod num;
178178
pub mod iter;
179+
pub mod iterator;
179180
pub mod to_str;
180181
pub mod to_bytes;
181182
pub mod clone;

branches/try/src/libcore/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub fn foldl<A,B,IA:BaseIter<A>>(self: &IA, b0: B, blk: &fn(&B, &A) -> B)
161161

162162
#[inline(always)]
163163
pub fn to_vec<A:Copy,IA:BaseIter<A>>(self: &IA) -> ~[A] {
164-
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(copy (*r), ~[*a]))
164+
map_to_vec(self, |&x| x)
165165
}
166166

167167
#[inline(always)]

branches/try/src/libcore/iterator.rs

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! Composable iterator objects
12+
13+
use prelude::*;
14+
15+
pub trait Iterator<T> {
16+
/// Advance the iterator and return the next value. Return `None` when the end is reached.
17+
fn next(&mut self) -> Option<T>;
18+
}
19+
20+
/// A shim implementing the `for` loop iteration protocol for iterator objects
21+
#[inline]
22+
pub fn advance<T, U: Iterator<T>>(iter: &mut U, f: &fn(T) -> bool) {
23+
loop {
24+
match iter.next() {
25+
Some(x) => {
26+
if !f(x) { return }
27+
}
28+
None => return
29+
}
30+
}
31+
}
32+
33+
pub struct ZipIterator<T, U> {
34+
priv a: T,
35+
priv b: U
36+
}
37+
38+
pub impl<A, B, T: Iterator<A>, U: Iterator<B>> ZipIterator<T, U> {
39+
#[inline(always)]
40+
fn new(a: T, b: U) -> ZipIterator<T, U> {
41+
ZipIterator{a: a, b: b}
42+
}
43+
}
44+
45+
impl<A, B, T: Iterator<A>, U: Iterator<B>> Iterator<(A, B)> for ZipIterator<T, U> {
46+
#[inline]
47+
fn next(&mut self) -> Option<(A, B)> {
48+
match (self.a.next(), self.b.next()) {
49+
(Some(x), Some(y)) => Some((x, y)),
50+
_ => None
51+
}
52+
}
53+
}
54+
55+
pub struct FilterIterator<'self, A, T> {
56+
priv iter: T,
57+
priv predicate: &'self fn(&A) -> bool
58+
}
59+
60+
pub impl<'self, A, T: Iterator<A>> FilterIterator<'self, A, T> {
61+
#[inline(always)]
62+
fn new(iter: T, predicate: &'self fn(&A) -> bool) -> FilterIterator<'self, A, T> {
63+
FilterIterator{iter: iter, predicate: predicate}
64+
}
65+
}
66+
67+
impl<'self, A, T: Iterator<A>> Iterator<A> for FilterIterator<'self, A, T> {
68+
#[inline]
69+
fn next(&mut self) -> Option<A> {
70+
for advance(self) |x| {
71+
if (self.predicate)(&x) {
72+
return Some(x);
73+
} else {
74+
loop
75+
}
76+
}
77+
None
78+
}
79+
}
80+
81+
pub struct MapIterator<'self, A, B, T> {
82+
priv iter: T,
83+
priv f: &'self fn(A) -> B
84+
}
85+
86+
pub impl<'self, A, B, T: Iterator<A>> MapIterator<'self, A, B, T> {
87+
#[inline(always)]
88+
fn new(iter: T, f: &'self fn(A) -> B) -> MapIterator<'self, A, B, T> {
89+
MapIterator{iter: iter, f: f}
90+
}
91+
}
92+
93+
impl<'self, A, B, T: Iterator<A>> Iterator<B> for MapIterator<'self, A, B, T> {
94+
#[inline]
95+
fn next(&mut self) -> Option<B> {
96+
match self.iter.next() {
97+
Some(a) => Some((self.f)(a)),
98+
_ => None
99+
}
100+
}
101+
}

branches/try/src/libcore/num/f32.rs

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
1313
use cmath;
1414
use libc::{c_float, c_int};
15-
use num::NumCast;
1615
use num::strconv;
1716
use num;
1817
use option::Option;
@@ -287,30 +286,6 @@ impl num::One for f32 {
287286
fn one() -> f32 { 1.0 }
288287
}
289288

290-
impl NumCast for f32 {
291-
/**
292-
* Cast `n` to an `f32`
293-
*/
294-
#[inline(always)]
295-
fn from<N:NumCast>(n: N) -> f32 { n.to_f32() }
296-
297-
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
298-
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
299-
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
300-
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
301-
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
302-
303-
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
304-
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
305-
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
306-
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
307-
#[inline(always)] fn to_int(&self) -> int { *self as int }
308-
309-
#[inline(always)] fn to_f32(&self) -> f32 { *self }
310-
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
311-
#[inline(always)] fn to_float(&self) -> float { *self as float }
312-
}
313-
314289
#[cfg(notest)]
315290
impl ops::Add<f32,f32> for f32 {
316291
fn add(&self, other: &f32) -> f32 { *self + *other }
@@ -580,63 +555,6 @@ impl num::FromStrRadix for f32 {
580555
}
581556
}
582557

583-
#[test]
584-
pub fn test_num() {
585-
let ten: f32 = num::cast(10);
586-
let two: f32 = num::cast(2);
587-
588-
assert!((ten.add(&two) == num::cast(12)));
589-
assert!((ten.sub(&two) == num::cast(8)));
590-
assert!((ten.mul(&two) == num::cast(20)));
591-
assert!((ten.div(&two) == num::cast(5)));
592-
assert!((ten.modulo(&two) == num::cast(0)));
593-
}
594-
595-
#[test]
596-
fn test_numcast() {
597-
assert!((20u == 20f32.to_uint()));
598-
assert!((20u8 == 20f32.to_u8()));
599-
assert!((20u16 == 20f32.to_u16()));
600-
assert!((20u32 == 20f32.to_u32()));
601-
assert!((20u64 == 20f32.to_u64()));
602-
assert!((20i == 20f32.to_int()));
603-
assert!((20i8 == 20f32.to_i8()));
604-
assert!((20i16 == 20f32.to_i16()));
605-
assert!((20i32 == 20f32.to_i32()));
606-
assert!((20i64 == 20f32.to_i64()));
607-
assert!((20f == 20f32.to_float()));
608-
assert!((20f32 == 20f32.to_f32()));
609-
assert!((20f64 == 20f32.to_f64()));
610-
611-
assert!((20f32 == NumCast::from(20u)));
612-
assert!((20f32 == NumCast::from(20u8)));
613-
assert!((20f32 == NumCast::from(20u16)));
614-
assert!((20f32 == NumCast::from(20u32)));
615-
assert!((20f32 == NumCast::from(20u64)));
616-
assert!((20f32 == NumCast::from(20i)));
617-
assert!((20f32 == NumCast::from(20i8)));
618-
assert!((20f32 == NumCast::from(20i16)));
619-
assert!((20f32 == NumCast::from(20i32)));
620-
assert!((20f32 == NumCast::from(20i64)));
621-
assert!((20f32 == NumCast::from(20f)));
622-
assert!((20f32 == NumCast::from(20f32)));
623-
assert!((20f32 == NumCast::from(20f64)));
624-
625-
assert!((20f32 == num::cast(20u)));
626-
assert!((20f32 == num::cast(20u8)));
627-
assert!((20f32 == num::cast(20u16)));
628-
assert!((20f32 == num::cast(20u32)));
629-
assert!((20f32 == num::cast(20u64)));
630-
assert!((20f32 == num::cast(20i)));
631-
assert!((20f32 == num::cast(20i8)));
632-
assert!((20f32 == num::cast(20i16)));
633-
assert!((20f32 == num::cast(20i32)));
634-
assert!((20f32 == num::cast(20i64)));
635-
assert!((20f32 == num::cast(20f)));
636-
assert!((20f32 == num::cast(20f32)));
637-
assert!((20f32 == num::cast(20f64)));
638-
}
639-
640558
//
641559
// Local Variables:
642560
// mode: rust

branches/try/src/libcore/num/f64.rs

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
1313
use cmath;
1414
use libc::{c_double, c_int};
15-
use num::NumCast;
1615
use num::strconv;
1716
use num;
1817
use option::Option;
@@ -299,30 +298,6 @@ impl cmp::Ord for f64 {
299298
fn gt(&self, other: &f64) -> bool { (*self) > (*other) }
300299
}
301300

302-
impl NumCast for f64 {
303-
/**
304-
* Cast `n` to an `f64`
305-
*/
306-
#[inline(always)]
307-
fn from<N:NumCast>(n: N) -> f64 { n.to_f64() }
308-
309-
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
310-
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
311-
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
312-
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
313-
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
314-
315-
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
316-
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
317-
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
318-
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
319-
#[inline(always)] fn to_int(&self) -> int { *self as int }
320-
321-
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
322-
#[inline(always)] fn to_f64(&self) -> f64 { *self }
323-
#[inline(always)] fn to_float(&self) -> float { *self as float }
324-
}
325-
326301
impl num::Zero for f64 {
327302
#[inline(always)]
328303
fn zero() -> f64 { 0.0 }
@@ -602,63 +577,6 @@ impl num::FromStrRadix for f64 {
602577
}
603578
}
604579

605-
#[test]
606-
pub fn test_num() {
607-
let ten: f64 = num::cast(10);
608-
let two: f64 = num::cast(2);
609-
610-
assert!((ten.add(&two) == num::cast(12)));
611-
assert!((ten.sub(&two) == num::cast(8)));
612-
assert!((ten.mul(&two) == num::cast(20)));
613-
assert!((ten.div(&two) == num::cast(5)));
614-
assert!((ten.modulo(&two) == num::cast(0)));
615-
}
616-
617-
#[test]
618-
fn test_numcast() {
619-
assert!((20u == 20f64.to_uint()));
620-
assert!((20u8 == 20f64.to_u8()));
621-
assert!((20u16 == 20f64.to_u16()));
622-
assert!((20u32 == 20f64.to_u32()));
623-
assert!((20u64 == 20f64.to_u64()));
624-
assert!((20i == 20f64.to_int()));
625-
assert!((20i8 == 20f64.to_i8()));
626-
assert!((20i16 == 20f64.to_i16()));
627-
assert!((20i32 == 20f64.to_i32()));
628-
assert!((20i64 == 20f64.to_i64()));
629-
assert!((20f == 20f64.to_float()));
630-
assert!((20f32 == 20f64.to_f32()));
631-
assert!((20f64 == 20f64.to_f64()));
632-
633-
assert!((20f64 == NumCast::from(20u)));
634-
assert!((20f64 == NumCast::from(20u8)));
635-
assert!((20f64 == NumCast::from(20u16)));
636-
assert!((20f64 == NumCast::from(20u32)));
637-
assert!((20f64 == NumCast::from(20u64)));
638-
assert!((20f64 == NumCast::from(20i)));
639-
assert!((20f64 == NumCast::from(20i8)));
640-
assert!((20f64 == NumCast::from(20i16)));
641-
assert!((20f64 == NumCast::from(20i32)));
642-
assert!((20f64 == NumCast::from(20i64)));
643-
assert!((20f64 == NumCast::from(20f)));
644-
assert!((20f64 == NumCast::from(20f32)));
645-
assert!((20f64 == NumCast::from(20f64)));
646-
647-
assert!((20f64 == num::cast(20u)));
648-
assert!((20f64 == num::cast(20u8)));
649-
assert!((20f64 == num::cast(20u16)));
650-
assert!((20f64 == num::cast(20u32)));
651-
assert!((20f64 == num::cast(20u64)));
652-
assert!((20f64 == num::cast(20i)));
653-
assert!((20f64 == num::cast(20i8)));
654-
assert!((20f64 == num::cast(20i16)));
655-
assert!((20f64 == num::cast(20i32)));
656-
assert!((20f64 == num::cast(20i64)));
657-
assert!((20f64 == num::cast(20f)));
658-
assert!((20f64 == num::cast(20f32)));
659-
assert!((20f64 == num::cast(20f64)));
660-
}
661-
662580
//
663581
// Local Variables:
664582
// mode: rust

0 commit comments

Comments
 (0)