libcollections: use unboxed closures in DList methods

This commit is contained in:
Jorge Aparicio 2014-12-05 16:55:16 -05:00
parent d5c332688c
commit 6f19f8d430

View File

@ -351,18 +351,16 @@ impl<T> DList<T> {
/// println!("{}", e); // prints 2, then 4, then 11, then 7, then 8
/// }
/// ```
pub fn insert_when(&mut self, elt: T, f: |&T, &T| -> bool) {
{
let mut it = self.iter_mut();
loop {
match it.peek_next() {
None => break,
Some(x) => if f(x, &elt) { break }
}
it.next();
pub fn insert_when<F>(&mut self, elt: T, mut f: F) where F: FnMut(&T, &T) -> bool {
let mut it = self.iter_mut();
loop {
match it.peek_next() {
None => break,
Some(x) => if f(x, &elt) { break }
}
it.insert_next(elt);
it.next();
}
it.insert_next(elt);
}
/// Merges `other` into this `DList`, using the function `f`.
@ -371,7 +369,7 @@ impl<T> DList<T> {
/// put `a` in the result if `f(a, b)` is true, and otherwise `b`.
///
/// This operation should compute in O(max(N, M)) time.
pub fn merge(&mut self, mut other: DList<T>, f: |&T, &T| -> bool) {
pub fn merge<F>(&mut self, mut other: DList<T>, mut f: F) where F: FnMut(&T, &T) -> bool {
{
let mut it = self.iter_mut();
loop {