Skip to content

Commit 0d39fc0

Browse files
author
Jorge Aparicio
committed
libcollections: use unboxed closures in TreeMap methods
1 parent 02e7389 commit 0d39fc0

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/libcollections/tree/map.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ impl<K, V> TreeMap<K, V> {
616616
/// ```
617617
#[inline]
618618
#[experimental = "likely to be renamed, may be removed"]
619-
pub fn find_with(&self, f:|&K| -> Ordering) -> Option<&V> {
619+
pub fn find_with<F>(&self, f: F) -> Option<&V> where F: FnMut(&K) -> Ordering {
620620
tree_find_with(&self.root, f)
621621
}
622622

@@ -641,7 +641,9 @@ impl<K, V> TreeMap<K, V> {
641641
/// ```
642642
#[inline]
643643
#[experimental = "likely to be renamed, may be removed"]
644-
pub fn find_with_mut<'a>(&'a mut self, f:|&K| -> Ordering) -> Option<&'a mut V> {
644+
pub fn find_with_mut<'a, F>(&'a mut self, f: F) -> Option<&'a mut V> where
645+
F: FnMut(&K) -> Ordering
646+
{
645647
tree_find_with_mut(&mut self.root, f)
646648
}
647649
}
@@ -1129,8 +1131,12 @@ fn split<K: Ord, V>(node: &mut Box<TreeNode<K, V>>) {
11291131
// Next 2 functions have the same convention: comparator gets
11301132
// at input current key and returns search_key cmp cur_key
11311133
// (i.e. search_key.cmp(&cur_key))
1132-
fn tree_find_with<'r, K, V>(node: &'r Option<Box<TreeNode<K, V>>>,
1133-
f: |&K| -> Ordering) -> Option<&'r V> {
1134+
fn tree_find_with<'r, K, V, F>(
1135+
node: &'r Option<Box<TreeNode<K, V>>>,
1136+
mut f: F,
1137+
) -> Option<&'r V> where
1138+
F: FnMut(&K) -> Ordering,
1139+
{
11341140
let mut current: &'r Option<Box<TreeNode<K, V>>> = node;
11351141
loop {
11361142
match *current {
@@ -1147,8 +1153,12 @@ fn tree_find_with<'r, K, V>(node: &'r Option<Box<TreeNode<K, V>>>,
11471153
}
11481154

11491155
// See comments above tree_find_with
1150-
fn tree_find_with_mut<'r, K, V>(node: &'r mut Option<Box<TreeNode<K, V>>>,
1151-
f: |&K| -> Ordering) -> Option<&'r mut V> {
1156+
fn tree_find_with_mut<'r, K, V, F>(
1157+
node: &'r mut Option<Box<TreeNode<K, V>>>,
1158+
mut f: F,
1159+
) -> Option<&'r mut V> where
1160+
F: FnMut(&K) -> Ordering,
1161+
{
11521162

11531163
let mut current = node;
11541164
loop {

0 commit comments

Comments
 (0)