Skip to content

Commit 9c70465

Browse files
author
Jorge Aparicio
committed
libcore: use unboxed closures in the fields of Splits
1 parent 30ea64e commit 9c70465

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/libcore/slice.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use default::Default;
4343
use iter::*;
4444
use kinds::Copy;
4545
use num::Int;
46-
use ops;
46+
use ops::{FnMut, mod};
4747
use option::Option;
4848
use option::Option::{None, Some};
4949
use ptr;
@@ -105,20 +105,23 @@ pub trait SlicePrelude<T> for Sized? {
105105
/// Returns an iterator over subslices separated by elements that match
106106
/// `pred`. The matched element is not contained in the subslices.
107107
#[unstable = "iterator type may change, waiting on unboxed closures"]
108-
fn split<'a>(&'a self, pred: |&T|: 'a -> bool) -> Splits<'a, T>;
108+
fn split<'a, P>(&'a self, pred: P) -> Splits<'a, T, P> where
109+
P: FnMut(&T) -> bool;
109110

110111
/// Returns an iterator over subslices separated by elements that match
111112
/// `pred`, limited to splitting at most `n` times. The matched element is
112113
/// not contained in the subslices.
113114
#[unstable = "iterator type may change"]
114-
fn splitn<'a>(&'a self, n: uint, pred: |&T|: 'a -> bool) -> SplitsN<Splits<'a, T>>;
115+
fn splitn<'a, P>(&'a self, n: uint, pred: P) -> SplitsN<Splits<'a, T, P>> where
116+
P: FnMut(&T) -> bool;
115117

116118
/// Returns an iterator over subslices separated by elements that match
117119
/// `pred` limited to splitting at most `n` times. This starts at the end of
118120
/// the slice and works backwards. The matched element is not contained in
119121
/// the subslices.
120122
#[unstable = "iterator type may change"]
121-
fn rsplitn<'a>(&'a self, n: uint, pred: |&T|: 'a -> bool) -> SplitsN<Splits<'a, T>>;
123+
fn rsplitn<'a, P>(&'a self, n: uint, pred: P) -> SplitsN<Splits<'a, T, P>> where
124+
P: FnMut(&T) -> bool;
122125

123126
/// Returns an iterator over all contiguous windows of length
124127
/// `size`. The windows overlap. If the slice is shorter than
@@ -470,7 +473,7 @@ impl<T> SlicePrelude<T> for [T] {
470473
}
471474

472475
#[inline]
473-
fn split<'a>(&'a self, pred: |&T|: 'a -> bool) -> Splits<'a, T> {
476+
fn split<'a, P>(&'a self, pred: P) -> Splits<'a, T, P> where P: FnMut(&T) -> bool {
474477
Splits {
475478
v: self,
476479
pred: pred,
@@ -479,7 +482,9 @@ impl<T> SlicePrelude<T> for [T] {
479482
}
480483

481484
#[inline]
482-
fn splitn<'a>(&'a self, n: uint, pred: |&T|: 'a -> bool) -> SplitsN<Splits<'a, T>> {
485+
fn splitn<'a, P>(&'a self, n: uint, pred: P) -> SplitsN<Splits<'a, T, P>> where
486+
P: FnMut(&T) -> bool,
487+
{
483488
SplitsN {
484489
iter: self.split(pred),
485490
count: n,
@@ -488,7 +493,9 @@ impl<T> SlicePrelude<T> for [T] {
488493
}
489494

490495
#[inline]
491-
fn rsplitn<'a>(&'a self, n: uint, pred: |&T|: 'a -> bool) -> SplitsN<Splits<'a, T>> {
496+
fn rsplitn<'a, P>(&'a self, n: uint, pred: P) -> SplitsN<Splits<'a, T, P>> where
497+
P: FnMut(&T) -> bool,
498+
{
492499
SplitsN {
493500
iter: self.split(pred),
494501
count: n,
@@ -1271,14 +1278,14 @@ trait SplitsIter<E>: DoubleEndedIterator<E> {
12711278
/// An iterator over subslices separated by elements that match a predicate
12721279
/// function.
12731280
#[experimental = "needs review"]
1274-
pub struct Splits<'a, T:'a> {
1281+
pub struct Splits<'a, T:'a, P> where P: FnMut(&T) -> bool {
12751282
v: &'a [T],
1276-
pred: |t: &T|: 'a -> bool,
1283+
pred: P,
12771284
finished: bool
12781285
}
12791286

12801287
#[experimental = "needs review"]
1281-
impl<'a, T> Iterator<&'a [T]> for Splits<'a, T> {
1288+
impl<'a, T, P> Iterator<&'a [T]> for Splits<'a, T, P> where P: FnMut(&T) -> bool {
12821289
#[inline]
12831290
fn next(&mut self) -> Option<&'a [T]> {
12841291
if self.finished { return None; }
@@ -1304,7 +1311,7 @@ impl<'a, T> Iterator<&'a [T]> for Splits<'a, T> {
13041311
}
13051312

13061313
#[experimental = "needs review"]
1307-
impl<'a, T> DoubleEndedIterator<&'a [T]> for Splits<'a, T> {
1314+
impl<'a, T, P> DoubleEndedIterator<&'a [T]> for Splits<'a, T, P> where P: FnMut(&T) -> bool {
13081315
#[inline]
13091316
fn next_back(&mut self) -> Option<&'a [T]> {
13101317
if self.finished { return None; }
@@ -1320,7 +1327,7 @@ impl<'a, T> DoubleEndedIterator<&'a [T]> for Splits<'a, T> {
13201327
}
13211328
}
13221329

1323-
impl<'a, T> SplitsIter<&'a [T]> for Splits<'a, T> {
1330+
impl<'a, T, P> SplitsIter<&'a [T]> for Splits<'a, T, P> where P: FnMut(&T) -> bool {
13241331
#[inline]
13251332
fn finish(&mut self) -> Option<&'a [T]> {
13261333
if self.finished { None } else { self.finished = true; Some(self.v) }

0 commit comments

Comments
 (0)