diff options
| author | Ben Blum <bblum@andrew.cmu.edu> | 2013-06-21 20:08:35 -0400 |
|---|---|---|
| committer | Ben Blum <bblum@andrew.cmu.edu> | 2013-06-29 04:39:34 -0400 |
| commit | ff4ab9e147b0be4126b8b70ca6ab27173a46077a (patch) | |
| tree | f028c640cd8a3efd7f8ec5661ba255d269250dbe /src/libstd | |
| parent | 89110fdf55c000096fc24a78d35256544c7b523f (diff) | |
| download | rust-ff4ab9e147b0be4126b8b70ca6ab27173a46077a.tar.gz rust-ff4ab9e147b0be4126b8b70ca6ab27173a46077a.zip | |
'Borrow' stack closures rather than copying them (e.g., "|x|f(x)"), in prep for making them noncopyable.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/hashmap.rs | 5 | ||||
| -rw-r--r-- | src/libstd/iterator.rs | 2 | ||||
| -rw-r--r-- | src/libstd/os.rs | 2 | ||||
| -rw-r--r-- | src/libstd/str.rs | 4 | ||||
| -rw-r--r-- | src/libstd/task/spawn.rs | 4 | ||||
| -rw-r--r-- | src/libstd/to_bytes.rs | 9 | ||||
| -rw-r--r-- | src/libstd/trie.rs | 6 | ||||
| -rw-r--r-- | src/libstd/vec.rs | 8 |
8 files changed, 24 insertions, 16 deletions
diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index bfa0f2fa124..7f9fb6ad938 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -671,7 +671,7 @@ impl<T:Hash + Eq> Set<T> for HashSet<T> { fn symmetric_difference(&self, other: &HashSet<T>, f: &fn(&T) -> bool) -> bool { - self.difference(other, f) && other.difference(self, f) + self.difference(other, |t| f(t)) && other.difference(self, |t| f(t)) } /// Visit the values representing the intersection @@ -681,7 +681,8 @@ impl<T:Hash + Eq> Set<T> for HashSet<T> { /// Visit the values representing the union fn union(&self, other: &HashSet<T>, f: &fn(&T) -> bool) -> bool { - self.iter().advance(f) && other.iter().advance(|v| self.contains(v) || f(v)) + self.iter().advance(|t| f(t)) && + other.iter().advance(|v| self.contains(v) || f(v)) } } diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 765bf3b36f2..976ca8bae7a 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -964,7 +964,7 @@ impl<'self, A, T: Iterator<A>, B, U: Iterator<B>> Iterator<B> for return Some(x) } } - match self.iter.next().map_consume(self.f) { + match self.iter.next().map_consume(|x| (self.f)(x)) { None => return None, next => self.subiter = next, } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 400a93ee28f..1fbcda12dce 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -595,7 +595,7 @@ pub fn walk_dir(p: &Path, f: &fn(&Path) -> bool) -> bool { let r = list_dir(p); r.iter().advance(|q| { let path = &p.push(*q); - f(path) && (!path_is_dir(path) || walk_dir(path, f)) + f(path) && (!path_is_dir(path) || walk_dir(path, |p| f(p))) }) } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 2144afc0fbd..e47800d70c6 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -463,7 +463,7 @@ pub fn each_split_within<'a>(ss: &'a str, cont }; - ss.iter().enumerate().advance(machine); + ss.iter().enumerate().advance(|x| machine(x)); // Let the automaton 'run out' by supplying trailing whitespace let mut fake_i = ss.len(); @@ -761,7 +761,7 @@ impl<'self> StrUtil for &'self str { // NB: len includes the trailing null. assert!(len > 0); if unsafe { *(ptr::offset(buf,len-1)) != 0 } { - to_owned(self).as_c_str(f) + to_owned(self).as_c_str(|s| f(s)) } else { f(buf as *libc::c_char) } diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 8f06fede057..c932a9660c2 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -230,11 +230,15 @@ fn each_ancestor(list: &mut AncestorList, // 'do_continue' - Did the forward_blk succeed at this point? (i.e., // should we recurse? or should our callers unwind?) + let forward_blk = Cell::new(forward_blk); + // The map defaults to None, because if ancestors is None, we're at // the end of the list, which doesn't make sense to coalesce. return do (**ancestors).map_default((None,false)) |ancestor_arc| { // NB: Takes a lock! (this ancestor node) do access_ancestors(ancestor_arc) |nobe| { + // Argh, but we couldn't give it to coalesce() otherwise. + let forward_blk = forward_blk.take(); // Check monotonicity assert!(last_generation > nobe.generation); /*##########################################################* diff --git a/src/libstd/to_bytes.rs b/src/libstd/to_bytes.rs index 6f0c615d007..d6e92dd679e 100644 --- a/src/libstd/to_bytes.rs +++ b/src/libstd/to_bytes.rs @@ -232,7 +232,8 @@ impl<A:IterBytes,B:IterBytes> IterBytes for (A,B) { #[inline] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { match *self { - (ref a, ref b) => { a.iter_bytes(lsb0, f) && b.iter_bytes(lsb0, f) } + (ref a, ref b) => { a.iter_bytes(lsb0, |b| f(b)) && + b.iter_bytes(lsb0, |b| f(b)) } } } } @@ -242,7 +243,9 @@ impl<A:IterBytes,B:IterBytes,C:IterBytes> IterBytes for (A,B,C) { fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { match *self { (ref a, ref b, ref c) => { - a.iter_bytes(lsb0, f) && b.iter_bytes(lsb0, f) && c.iter_bytes(lsb0, f) + a.iter_bytes(lsb0, |b| f(b)) && + b.iter_bytes(lsb0, |b| f(b)) && + c.iter_bytes(lsb0, |b| f(b)) } } } @@ -296,7 +299,7 @@ impl<A:IterBytes> IterBytes for Option<A> { #[inline] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { match *self { - Some(ref a) => 0u8.iter_bytes(lsb0, f) && a.iter_bytes(lsb0, f), + Some(ref a) => 0u8.iter_bytes(lsb0, |b| f(b)) && a.iter_bytes(lsb0, |b| f(b)), None => 1u8.iter_bytes(lsb0, f) } } diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index 8f70c75439a..b9b03ea5661 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -251,7 +251,7 @@ impl<T> TrieNode<T> { fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool { for uint::range(0, self.children.len()) |idx| { match self.children[idx] { - Internal(ref x) => if !x.each(f) { return false }, + Internal(ref x) => if !x.each(|i,t| f(i,t)) { return false }, External(k, ref v) => if !f(&k, v) { return false }, Nothing => () } @@ -262,7 +262,7 @@ impl<T> TrieNode<T> { fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool { for uint::range_rev(self.children.len(), 0) |idx| { match self.children[idx - 1] { - Internal(ref x) => if !x.each_reverse(f) { return false }, + Internal(ref x) => if !x.each_reverse(|i,t| f(i,t)) { return false }, External(k, ref v) => if !f(&k, v) { return false }, Nothing => () } @@ -273,7 +273,7 @@ impl<T> TrieNode<T> { fn mutate_values<'a>(&'a mut self, f: &fn(&uint, &mut T) -> bool) -> bool { for self.children.mut_iter().advance |child| { match *child { - Internal(ref mut x) => if !x.mutate_values(f) { + Internal(ref mut x) => if !x.mutate_values(|i,t| f(i,t)) { return false }, External(k, ref mut v) => if !f(&k, v) { return false }, diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 8555d99255d..4e7943f7cfd 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -191,7 +191,7 @@ pub fn split<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] { let mut start = 0u; let mut result = ~[]; while start < ln { - match position_between(v, start, ln, f) { + match position_between(v, start, ln, |t| f(t)) { None => break, Some(i) => { result.push(v.slice(start, i).to_owned()); @@ -215,7 +215,7 @@ pub fn splitn<T:Copy>(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] { let mut count = n; let mut result = ~[]; while start < ln && count > 0u { - match position_between(v, start, ln, f) { + match position_between(v, start, ln, |t| f(t)) { None => break, Some(i) => { result.push(v.slice(start, i).to_owned()); @@ -240,7 +240,7 @@ pub fn rsplit<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] { let mut end = ln; let mut result = ~[]; while end > 0 { - match rposition_between(v, 0, end, f) { + match rposition_between(v, 0, end, |t| f(t)) { None => break, Some(i) => { result.push(v.slice(i + 1, end).to_owned()); @@ -265,7 +265,7 @@ pub fn rsplitn<T:Copy>(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] { let mut count = n; let mut result = ~[]; while end > 0u && count > 0u { - match rposition_between(v, 0u, end, f) { + match rposition_between(v, 0u, end, |t| f(t)) { None => break, Some(i) => { result.push(v.slice(i + 1u, end).to_owned()); |
