Skip to content

Commit fbed758

Browse files
committed
---
yaml --- r: 65042 b: refs/heads/master c: a9c465c h: refs/heads/master v: v3
1 parent 131f768 commit fbed758

File tree

14 files changed

+255
-309
lines changed

14 files changed

+255
-309
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: e91daaa8a9390ccf760b3ba7f965b2863103d993
2+
refs/heads/master: a9c465ce1f1caaae58a31c57f665217ee58bb876
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/src/libcore/bool.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ pub fn is_false(v: bool) -> bool { !v }
4949
/// Parse logic value from `s`
5050
impl FromStr for bool {
5151
fn from_str(s: &str) -> Option<bool> {
52-
match s {
53-
"true" => Some(true),
54-
"false" => Some(false),
55-
_ => None,
52+
if s == "true" {
53+
Some(true)
54+
} else if s == "false" {
55+
Some(false)
56+
} else {
57+
None
5658
}
5759
}
5860
}

trunk/src/libcore/cmp.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,12 @@ totalord_impl!(uint)
127127

128128
totalord_impl!(char)
129129

130-
/// Compares (a1, b1) against (a2, b2), where the a values are more significant.
131130
pub fn cmp2<A:TotalOrd,B:TotalOrd>(
132131
a1: &A, b1: &B,
133132
a2: &A, b2: &B) -> Ordering
134133
{
134+
//! Compares (a1, b1) against (a2, b2), where the a values are more significant.
135+
135136
match a1.cmp(a2) {
136137
Less => Less,
137138
Greater => Greater,

trunk/src/libcore/either.rs

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,26 @@ pub enum Either<T, U> {
2626
Right(U)
2727
}
2828

29-
/// Applies a function based on the given either value
30-
///
31-
/// If `value` is left(T) then `f_left` is applied to its contents, if
32-
/// `value` is right(U) then `f_right` is applied to its contents, and the
33-
/// result is returned.
3429
#[inline(always)]
3530
pub fn either<T, U, V>(f_left: &fn(&T) -> V,
3631
f_right: &fn(&U) -> V, value: &Either<T, U>) -> V {
32+
/*!
33+
* Applies a function based on the given either value
34+
*
35+
* If `value` is left(T) then `f_left` is applied to its contents, if
36+
* `value` is right(U) then `f_right` is applied to its contents, and the
37+
* result is returned.
38+
*/
39+
3740
match *value {
38-
Left(ref l) => f_left(l),
39-
Right(ref r) => f_right(r)
41+
Left(ref l) => f_left(l),
42+
Right(ref r) => f_right(r)
4043
}
4144
}
4245

43-
/// Extracts from a vector of either all the left values
4446
pub fn lefts<T:Copy,U>(eithers: &[Either<T, U>]) -> ~[T] {
47+
//! Extracts from a vector of either all the left values
48+
4549
do vec::build_sized(eithers.len()) |push| {
4650
for eithers.each |elt| {
4751
match *elt {
@@ -52,8 +56,9 @@ pub fn lefts<T:Copy,U>(eithers: &[Either<T, U>]) -> ~[T] {
5256
}
5357
}
5458

55-
/// Extracts from a vector of either all the right values
5659
pub fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
60+
//! Extracts from a vector of either all the right values
61+
5762
do vec::build_sized(eithers.len()) |push| {
5863
for eithers.each |elt| {
5964
match *elt {
@@ -64,73 +69,80 @@ pub fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
6469
}
6570
}
6671

67-
/// Extracts from a vector of either all the left values and right values
68-
///
69-
/// Returns a structure containing a vector of left values and a vector of
70-
/// right values.
71-
pub fn partition<T, U>(eithers: ~[Either<T, U>]) -> (~[T], ~[U]) {
72+
pub fn partition<T, U>(eithers: ~[Either<T, U>])
73+
-> (~[T], ~[U]) {
74+
/*!
75+
* Extracts from a vector of either all the left values and right values
76+
*
77+
* Returns a structure containing a vector of left values and a vector of
78+
* right values.
79+
*/
80+
7281
let mut lefts: ~[T] = ~[];
7382
let mut rights: ~[U] = ~[];
7483
do vec::consume(eithers) |_i, elt| {
7584
match elt {
76-
Left(l) => lefts.push(l),
77-
Right(r) => rights.push(r)
85+
Left(l) => lefts.push(l),
86+
Right(r) => rights.push(r)
7887
}
7988
}
8089
return (lefts, rights);
8190
}
8291

83-
/// Flips between left and right of a given either
8492
#[inline(always)]
8593
pub fn flip<T, U>(eith: Either<T, U>) -> Either<U, T> {
94+
//! Flips between left and right of a given either
95+
8696
match eith {
87-
Right(r) => Left(r),
88-
Left(l) => Right(l)
97+
Right(r) => Left(r),
98+
Left(l) => Right(l)
8999
}
90100
}
91101

92-
/// Converts either::t to a result::t
93-
///
94-
/// Converts an `either` type to a `result` type, making the "right" choice
95-
/// an ok result, and the "left" choice a fail
96102
#[inline(always)]
97-
pub fn to_result<T, U>(eith: Either<T, U>) -> Result<U, T> {
103+
pub fn to_result<T, U>(eith: Either<T, U>)
104+
-> Result<U, T> {
105+
/*!
106+
* Converts either::t to a result::t
107+
*
108+
* Converts an `either` type to a `result` type, making the "right" choice
109+
* an ok result, and the "left" choice a fail
110+
*/
111+
98112
match eith {
99-
Right(r) => result::Ok(r),
100-
Left(l) => result::Err(l)
113+
Right(r) => result::Ok(r),
114+
Left(l) => result::Err(l)
101115
}
102116
}
103117

104-
/// Checks whether the given value is a left
105118
#[inline(always)]
106119
pub fn is_left<T, U>(eith: &Either<T, U>) -> bool {
107-
match *eith {
108-
Left(_) => true,
109-
_ => false
110-
}
120+
//! Checks whether the given value is a left
121+
122+
match *eith { Left(_) => true, _ => false }
111123
}
112124

113-
/// Checks whether the given value is a right
114125
#[inline(always)]
115126
pub fn is_right<T, U>(eith: &Either<T, U>) -> bool {
116-
match *eith {
117-
Right(_) => true,
118-
_ => false
119-
}
127+
//! Checks whether the given value is a right
128+
129+
match *eith { Right(_) => true, _ => false }
120130
}
121131

122-
/// Retrieves the value in the left branch. Fails if the either is Right.
123132
#[inline(always)]
124133
pub fn unwrap_left<T,U>(eith: Either<T,U>) -> T {
134+
//! Retrieves the value in the left branch. Fails if the either is Right.
135+
125136
match eith {
126137
Left(x) => x,
127138
Right(_) => fail!("either::unwrap_left Right")
128139
}
129140
}
130141

131-
/// Retrieves the value in the right branch. Fails if the either is Left.
132142
#[inline(always)]
133143
pub fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
144+
//! Retrieves the value in the right branch. Fails if the either is Left.
145+
134146
match eith {
135147
Right(x) => x,
136148
Left(_) => fail!("either::unwrap_right Left")

trunk/src/libcore/iterator.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ pub trait IteratorUtil<A> {
4949
fn advance(&mut self, f: &fn(A) -> bool) -> bool;
5050
fn to_vec(self) -> ~[A];
5151
fn nth(&mut self, n: uint) -> A;
52-
fn first(&mut self) -> A;
5352
fn last(&mut self) -> A;
5453
fn fold<B>(&mut self, start: B, f: &fn(B, A) -> B) -> B;
5554
fn count(&mut self) -> uint;
@@ -168,15 +167,6 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
168167
}
169168
}
170169

171-
// Get first elemet of an iterator.
172-
#[inline(always)]
173-
fn first(&mut self) -> A {
174-
match self.next() {
175-
Some(x) => x ,
176-
None => fail!("cannot get first element")
177-
}
178-
}
179-
180170
// Get last element of an iterator.
181171
//
182172
// If the iterator have an infinite length, this method won't return.
@@ -700,20 +690,6 @@ mod tests {
700690
v.iter().nth(5);
701691
}
702692

703-
#[test]
704-
fn test_iterator_first() {
705-
let v = &[0, 1, 2, 3, 4];
706-
assert_eq!(v.iter().first(), &0);
707-
assert_eq!(v.slice(2, 5).iter().first(), &2);
708-
}
709-
710-
#[test]
711-
#[should_fail]
712-
fn test_iterator_first_fail() {
713-
let v: &[uint] = &[];
714-
v.iter().first();
715-
}
716-
717693
#[test]
718694
fn test_iterator_last() {
719695
let v = &[0, 1, 2, 3, 4];

trunk/src/libcore/managed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ pub mod raw {
3535

3636
}
3737

38-
/// Determine if two shared boxes point to the same object
3938
#[inline(always)]
4039
pub fn ptr_eq<T>(a: @T, b: @T) -> bool {
40+
//! Determine if two shared boxes point to the same object
4141
let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b);
4242
a_ptr == b_ptr
4343
}
4444

45-
/// Determine if two mutable shared boxes point to the same object
4645
#[inline(always)]
4746
pub fn mut_ptr_eq<T>(a: @mut T, b: @mut T) -> bool {
47+
//! Determine if two mutable shared boxes point to the same object
4848
let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b);
4949
a_ptr == b_ptr
5050
}

trunk/src/libcore/num/f32.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -248,27 +248,15 @@ impl Orderable for f32 {
248248
if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmax(*self, *other) }
249249
}
250250

251-
#[cfg(stage0)]
251+
/// Returns the number constrained within the range `mn <= self <= mx`.
252+
/// If any of the numbers are `NaN` then `NaN` is returned.
252253
#[inline(always)]
253254
fn clamp(&self, mn: &f32, mx: &f32) -> f32 {
254255
if self.is_NaN() { *self }
255256
else if !(*self <= *mx) { *mx }
256257
else if !(*self >= *mn) { *mn }
257258
else { *self }
258259
}
259-
260-
/// Returns the number constrained within the range `mn <= self <= mx`.
261-
/// If any of the numbers are `NaN` then `NaN` is returned.
262-
#[cfg(not(stage0))]
263-
#[inline(always)]
264-
fn clamp(&self, mn: &f32, mx: &f32) -> f32 {
265-
cond!(
266-
(self.is_NaN()) { *self }
267-
(!(*self <= *mx)) { *mx }
268-
(!(*self >= *mn)) { *mn }
269-
_ { *self }
270-
)
271-
}
272260
}
273261

274262
impl Zero for f32 {

trunk/src/libcore/num/f64.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -270,27 +270,15 @@ impl Orderable for f64 {
270270
if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmax(*self, *other) }
271271
}
272272

273-
#[cfg(stage0)]
273+
/// Returns the number constrained within the range `mn <= self <= mx`.
274+
/// If any of the numbers are `NaN` then `NaN` is returned.
274275
#[inline(always)]
275276
fn clamp(&self, mn: &f64, mx: &f64) -> f64 {
276277
if self.is_NaN() { *self }
277278
else if !(*self <= *mx) { *mx }
278279
else if !(*self >= *mn) { *mn }
279280
else { *self }
280281
}
281-
282-
/// Returns the number constrained within the range `mn <= self <= mx`.
283-
/// If any of the numbers are `NaN` then `NaN` is returned.
284-
#[cfg(not(stage0))]
285-
#[inline(always)]
286-
fn clamp(&self, mn: &f64, mx: &f64) -> f64 {
287-
cond!(
288-
(self.is_NaN()) { *self }
289-
(!(*self <= *mx)) { *mx }
290-
(!(*self >= *mn)) { *mn }
291-
_ { *self }
292-
)
293-
}
294282
}
295283

296284
impl Zero for f64 {

trunk/src/libcore/num/int-template.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,23 +187,11 @@ impl Orderable for T {
187187
if *self > *other { *self } else { *other }
188188
}
189189

190-
#[cfg(stage0)]
191190
#[inline(always)]
192191
fn clamp(&self, mn: &T, mx: &T) -> T {
193192
if *self > *mx { *mx } else
194193
if *self < *mn { *mn } else { *self }
195194
}
196-
197-
/// Returns the number constrained within the range `mn <= self <= mx`.
198-
#[cfg(not(stage0))]
199-
#[inline(always)]
200-
fn clamp(&self, mn: &T, mx: &T) -> T {
201-
cond!(
202-
(*self > *mx) { *mx }
203-
(*self < *mn) { *mn }
204-
_ { *self }
205-
)
206-
}
207195
}
208196

209197
impl Zero for T {

trunk/src/libcore/num/uint-template.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,23 +153,11 @@ impl Orderable for T {
153153
if *self > *other { *self } else { *other }
154154
}
155155

156-
#[cfg(stage0)]
157156
#[inline(always)]
158157
fn clamp(&self, mn: &T, mx: &T) -> T {
159158
if *self > *mx { *mx } else
160159
if *self < *mn { *mn } else { *self }
161160
}
162-
163-
/// Returns the number constrained within the range `mn <= self <= mx`.
164-
#[cfg(not(stage0))]
165-
#[inline(always)]
166-
fn clamp(&self, mn: &T, mx: &T) -> T {
167-
cond!(
168-
(*self > *mx) { *mx }
169-
(*self < *mn) { *mn }
170-
_ { *self }
171-
)
172-
}
173161
}
174162

175163
impl Zero for T {

0 commit comments

Comments
 (0)