Skip to content

Commit ac20263

Browse files
committed
---
yaml --- r: 56222 b: refs/heads/auto c: a523abd h: refs/heads/master v: v3
1 parent 9c3e7b8 commit ac20263

File tree

14 files changed

+371
-451
lines changed

14 files changed

+371
-451
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: 8796c9fe2d4898b9984d1de53a18c15dcb6eaf08
17+
refs/heads/auto: a523abd75c619be64cb8c0613431150e0913c934
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/src/libcore/io.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ pub trait ReaderUtil {
176176
fn read_bytes(&self, len: uint) -> ~[u8];
177177

178178
/**
179-
* Reads up until a specific byte is seen or EOF.
179+
* Reads up until a specific character or EOF.
180180
*
181181
* The `include` parameter specifies if the character should be included
182182
* in the returned string.
@@ -185,7 +185,7 @@ pub trait ReaderUtil {
185185
*
186186
* None right now.
187187
*/
188-
fn read_until(&self, c: u8, include: bool) -> ~str;
188+
fn read_until(&self, c: char, include: bool) -> ~str;
189189

190190
/**
191191
* Reads up until the first '\n' or EOF.
@@ -577,7 +577,7 @@ impl<T:Reader> ReaderUtil for T {
577577
bytes
578578
}
579579

580-
fn read_until(&self, c: u8, include: bool) -> ~str {
580+
fn read_until(&self, c: char, include: bool) -> ~str {
581581
let mut bytes = ~[];
582582
loop {
583583
let ch = self.read_byte();
@@ -593,7 +593,7 @@ impl<T:Reader> ReaderUtil for T {
593593
}
594594

595595
fn read_line(&self) -> ~str {
596-
self.read_until('\n' as u8, false)
596+
self.read_until('\n', false)
597597
}
598598

599599
fn read_chars(&self, n: uint) -> ~[char] {
@@ -667,7 +667,7 @@ impl<T:Reader> ReaderUtil for T {
667667
}
668668

669669
fn read_c_str(&self) -> ~str {
670-
self.read_until(0u8, false)
670+
self.read_until(0 as char, false)
671671
}
672672

673673
fn read_whole_stream(&self) -> ~[u8] {
@@ -693,7 +693,7 @@ impl<T:Reader> ReaderUtil for T {
693693
// include the \n, so that we can distinguish an entirely empty
694694
// line read after "...\n", and the trailing empty line in
695695
// "...\n\n".
696-
let mut line = self.read_until('\n' as u8, true);
696+
let mut line = self.read_until('\n', true);
697697

698698
// blank line at the end of the reader is ignored
699699
if self.eof() && line.is_empty() { break; }

branches/auto/src/libcore/iterator.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub trait IteratorUtil<A> {
2222
// FIXME: #5898: should be called map
2323
fn transform<'r, B>(self, f: &'r fn(A) -> B) -> MapIterator<'r, A, B, Self>;
2424
fn filter<'r>(self, predicate: &'r fn(&A) -> bool) -> FilterIterator<'r, A, Self>;
25+
fn dropwhile<'r>(self, predicate: &'r fn(&A) -> bool) -> DropWhileIterator<'r, A, Self>;
26+
fn takewhile<'r>(self, predicate: &'r fn(&A) -> bool) -> TakeWhileIterator<'r, A, Self>;
2527
fn enumerate(self) -> EnumerateIterator<Self>;
2628
fn advance(&mut self, f: &fn(A) -> bool);
2729
}
@@ -48,6 +50,16 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
4850
EnumerateIterator{iter: self, count: 0}
4951
}
5052

53+
#[inline(always)]
54+
fn dropwhile<'r>(self, predicate: &'r fn(&A) -> bool) -> DropWhileIterator<'r, A, T> {
55+
DropWhileIterator{iter: self, flag: false, predicate: predicate}
56+
}
57+
58+
#[inline(always)]
59+
fn takewhile<'r>(self, predicate: &'r fn(&A) -> bool) -> TakeWhileIterator<'r, A, T> {
60+
TakeWhileIterator{iter: self, flag: false, predicate: predicate}
61+
}
62+
5163
/// A shim implementing the `for` loop iteration protocol for iterator objects
5264
#[inline]
5365
fn advance(&mut self, f: &fn(A) -> bool) {
@@ -129,3 +141,61 @@ impl<A, T: Iterator<A>> Iterator<(uint, A)> for EnumerateIterator<T> {
129141
}
130142
}
131143
}
144+
145+
pub struct DropWhileIterator<'self, A, T> {
146+
priv iter: T,
147+
priv flag: bool,
148+
priv predicate: &'self fn(&A) -> bool
149+
}
150+
151+
impl<'self, A, T: Iterator<A>> Iterator<A> for DropWhileIterator<'self, A, T> {
152+
#[inline]
153+
fn next(&mut self) -> Option<A> {
154+
let mut next = self.iter.next();
155+
if self.flag {
156+
next
157+
} else {
158+
loop {
159+
match next {
160+
Some(x) => {
161+
if (self.predicate)(&x) {
162+
next = self.iter.next();
163+
loop
164+
} else {
165+
self.flag = true;
166+
return Some(x)
167+
}
168+
}
169+
None => return None
170+
}
171+
}
172+
}
173+
}
174+
}
175+
176+
pub struct TakeWhileIterator<'self, A, T> {
177+
priv iter: T,
178+
priv flag: bool,
179+
priv predicate: &'self fn(&A) -> bool
180+
}
181+
182+
impl<'self, A, T: Iterator<A>> Iterator<A> for TakeWhileIterator<'self, A, T> {
183+
#[inline]
184+
fn next(&mut self) -> Option<A> {
185+
if self.flag {
186+
None
187+
} else {
188+
match self.iter.next() {
189+
Some(x) => {
190+
if (self.predicate)(&x) {
191+
Some(x)
192+
} else {
193+
self.flag = true;
194+
None
195+
}
196+
}
197+
None => None
198+
}
199+
}
200+
}
201+
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,32 +288,26 @@ impl num::One for f32 {
288288

289289
#[cfg(notest)]
290290
impl ops::Add<f32,f32> for f32 {
291-
#[inline(always)]
292291
fn add(&self, other: &f32) -> f32 { *self + *other }
293292
}
294293
#[cfg(notest)]
295294
impl ops::Sub<f32,f32> for f32 {
296-
#[inline(always)]
297295
fn sub(&self, other: &f32) -> f32 { *self - *other }
298296
}
299297
#[cfg(notest)]
300298
impl ops::Mul<f32,f32> for f32 {
301-
#[inline(always)]
302299
fn mul(&self, other: &f32) -> f32 { *self * *other }
303300
}
304301
#[cfg(notest)]
305302
impl ops::Div<f32,f32> for f32 {
306-
#[inline(always)]
307303
fn div(&self, other: &f32) -> f32 { *self / *other }
308304
}
309305
#[cfg(notest)]
310306
impl ops::Modulo<f32,f32> for f32 {
311-
#[inline(always)]
312307
fn modulo(&self, other: &f32) -> f32 { *self % *other }
313308
}
314309
#[cfg(notest)]
315310
impl ops::Neg<f32> for f32 {
316-
#[inline(always)]
317311
fn neg(&self) -> f32 { -*self }
318312
}
319313

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,32 +310,26 @@ impl num::One for f64 {
310310

311311
#[cfg(notest)]
312312
impl ops::Add<f64,f64> for f64 {
313-
#[inline(always)]
314313
fn add(&self, other: &f64) -> f64 { *self + *other }
315314
}
316315
#[cfg(notest)]
317316
impl ops::Sub<f64,f64> for f64 {
318-
#[inline(always)]
319317
fn sub(&self, other: &f64) -> f64 { *self - *other }
320318
}
321319
#[cfg(notest)]
322320
impl ops::Mul<f64,f64> for f64 {
323-
#[inline(always)]
324321
fn mul(&self, other: &f64) -> f64 { *self * *other }
325322
}
326323
#[cfg(notest)]
327324
impl ops::Div<f64,f64> for f64 {
328-
#[inline(always)]
329325
fn div(&self, other: &f64) -> f64 { *self / *other }
330326
}
331327
#[cfg(notest)]
332328
impl ops::Modulo<f64,f64> for f64 {
333-
#[inline(always)]
334329
fn modulo(&self, other: &f64) -> f64 { *self % *other }
335330
}
336331
#[cfg(notest)]
337332
impl ops::Neg<f64> for f64 {
338-
#[inline(always)]
339333
fn neg(&self) -> f64 { -*self }
340334
}
341335

0 commit comments

Comments
 (0)