core: Don't copy elements in filter_map

This commit is contained in:
Brian Anderson 2012-03-17 18:17:27 -07:00
parent 35e9970e29
commit 3ee4a15e5e

View file

@ -430,11 +430,11 @@ Apply a function to each element of a vector and return the results
If function `f` returns `none` then that element is excluded from If function `f` returns `none` then that element is excluded from
the resulting vector. the resulting vector.
"] "]
fn filter_map<T: copy, U: copy>(v: [const T], f: fn(T) -> option<U>) fn filter_map<T: copy, U: copy>(v: [T], f: fn(T) -> option<U>)
-> [U] { -> [U] {
let mut result = []; let mut result = [];
for elem: T in v { for elem: T in v {
alt f(copy elem) { alt f(elem) {
none {/* no-op */ } none {/* no-op */ }
some(result_elem) { result += [result_elem]; } some(result_elem) { result += [result_elem]; }
} }