Using const vector slices for more vec functions.
This commit is contained in:
parent
0f20cae37f
commit
0eed37da29
5 changed files with 39 additions and 24 deletions
|
@ -652,15 +652,16 @@ fn install_named(c: cargo, wd: str, name: str) {
|
|||
|
||||
fn install_uuid_specific(c: cargo, wd: str, src: str, uuid: str) {
|
||||
alt c.sources.find(src) {
|
||||
some(s) {
|
||||
if vec::any(copy s.packages, { |p|
|
||||
if p.uuid == uuid {
|
||||
install_package(c, wd, p);
|
||||
true
|
||||
} else { false }
|
||||
}) { ret; }
|
||||
}
|
||||
_ { }
|
||||
some(s) {
|
||||
let packages = copy s.packages;
|
||||
if vec::any(packages, { |p|
|
||||
if p.uuid == uuid {
|
||||
install_package(c, wd, p);
|
||||
true
|
||||
} else { false }
|
||||
}) { ret; }
|
||||
}
|
||||
_ { }
|
||||
}
|
||||
error("Can't find package " + src + "/" + uuid);
|
||||
}
|
||||
|
@ -668,7 +669,8 @@ fn install_uuid_specific(c: cargo, wd: str, src: str, uuid: str) {
|
|||
fn install_named_specific(c: cargo, wd: str, src: str, name: str) {
|
||||
alt c.sources.find(src) {
|
||||
some(s) {
|
||||
if vec::any(copy s.packages, { |p|
|
||||
let packages = copy s.packages;
|
||||
if vec::any(packages, { |p|
|
||||
if p.name == name {
|
||||
install_package(c, wd, p);
|
||||
true
|
||||
|
|
|
@ -33,6 +33,7 @@ export grow;
|
|||
export grow_fn;
|
||||
export grow_set;
|
||||
export map;
|
||||
export mapi;
|
||||
export map2;
|
||||
export flat_map;
|
||||
export filter_map;
|
||||
|
@ -440,13 +441,23 @@ fn grow_set<T: copy>(&v: [mut T], index: uint, initval: T, val: T) {
|
|||
#[doc = "
|
||||
Apply a function to each element of a vector and return the results
|
||||
"]
|
||||
fn map<T, U>(v: [T], f: fn(T) -> U) -> [U] {
|
||||
fn map<T, U>(v: [const T]/&, f: fn(T) -> U) -> [U] {
|
||||
let mut result = [];
|
||||
reserve(result, len(v));
|
||||
for each(v) {|elem| result += [f(elem)]; }
|
||||
ret result;
|
||||
}
|
||||
|
||||
#[doc = "
|
||||
Apply a function to each element of a vector and return the results
|
||||
"]
|
||||
fn mapi<T, U>(v: [const T]/&, f: fn(uint, T) -> U) -> [U] {
|
||||
let mut result = [];
|
||||
reserve(result, len(v));
|
||||
for eachi(v) {|i, elem| result += [f(i, elem)]; }
|
||||
ret result;
|
||||
}
|
||||
|
||||
#[doc = "
|
||||
Apply a function to each element of a vector and return a concatenation
|
||||
of each result vector
|
||||
|
@ -537,7 +548,7 @@ fn foldl<T: copy, U>(z: T, v: [const U], p: fn(T, U) -> T) -> T {
|
|||
}
|
||||
|
||||
#[doc = "Reduce a vector from right to left"]
|
||||
fn foldr<T, U: copy>(v: [const T], z: U, p: fn(T, U) -> U) -> U {
|
||||
fn foldr<T, U: copy>(v: [const T]/&, z: U, p: fn(T, U) -> U) -> U {
|
||||
let mut accum = z;
|
||||
riter(v) { |elt|
|
||||
accum = p(elt, accum);
|
||||
|
@ -550,7 +561,7 @@ Return true if a predicate matches any elements
|
|||
|
||||
If the vector contains no elements then false is returned.
|
||||
"]
|
||||
fn any<T>(v: [T], f: fn(T) -> bool) -> bool {
|
||||
fn any<T>(v: [const T]/&, f: fn(T) -> bool) -> bool {
|
||||
for each(v) {|elem| if f(elem) { ret true; } }
|
||||
ret false;
|
||||
}
|
||||
|
@ -560,7 +571,7 @@ Return true if a predicate matches any elements in both vectors.
|
|||
|
||||
If the vectors contains no elements then false is returned.
|
||||
"]
|
||||
fn any2<T, U>(v0: [const T], v1: [U], f: fn(T, U) -> bool) -> bool {
|
||||
fn any2<T, U>(v0: [const T]/&, v1: [const U]/&, f: fn(T, U) -> bool) -> bool {
|
||||
let v0_len = len(v0);
|
||||
let v1_len = len(v1);
|
||||
let mut i = 0u;
|
||||
|
@ -576,7 +587,7 @@ Return true if a predicate matches all elements
|
|||
|
||||
If the vector contains no elements then true is returned.
|
||||
"]
|
||||
fn all<T>(v: [T], f: fn(T) -> bool) -> bool {
|
||||
fn all<T>(v: [const T]/&, f: fn(T) -> bool) -> bool {
|
||||
for each(v) {|elem| if !f(elem) { ret false; } }
|
||||
ret true;
|
||||
}
|
||||
|
@ -586,7 +597,7 @@ Return true if a predicate matches all elements
|
|||
|
||||
If the vector contains no elements then true is returned.
|
||||
"]
|
||||
fn alli<T>(v: [T], f: fn(uint, T) -> bool) -> bool {
|
||||
fn alli<T>(v: [const T]/&, f: fn(uint, T) -> bool) -> bool {
|
||||
for eachi(v) {|i, elem| if !f(i, elem) { ret false; } }
|
||||
ret true;
|
||||
}
|
||||
|
@ -596,7 +607,7 @@ Return true if a predicate matches all elements in both vectors.
|
|||
|
||||
If the vectors are not the same size then false is returned.
|
||||
"]
|
||||
fn all2<T, U>(v0: [const T], v1: [const U], f: fn(T, U) -> bool) -> bool {
|
||||
fn all2<T, U>(v0: [const T]/&, v1: [const U]/&, f: fn(T, U) -> bool) -> bool {
|
||||
let v0_len = len(v0);
|
||||
if v0_len != len(v1) { ret false; }
|
||||
let mut i = 0u;
|
||||
|
@ -899,7 +910,7 @@ Iterates over a vector in reverse
|
|||
Iterates over vector `v` and, for each element, calls function `f` with the
|
||||
element's value.
|
||||
"]
|
||||
fn riter<T>(v: [const T], f: fn(T)) {
|
||||
fn riter<T>(v: [const T]/&, f: fn(T)) {
|
||||
riteri(v) { |_i, v| f(v) }
|
||||
}
|
||||
|
||||
|
@ -909,7 +920,7 @@ Iterates over a vector's elements and indexes in reverse
|
|||
Iterates over vector `v` and, for each element, calls function `f` with the
|
||||
element's value and index.
|
||||
"]
|
||||
fn riteri<T>(v: [const T], f: fn(uint, T)) {
|
||||
fn riteri<T>(v: [const T]/&, f: fn(uint, T)) {
|
||||
let mut i = len(v);
|
||||
while 0u < i {
|
||||
i -= 1u;
|
||||
|
@ -1115,8 +1126,7 @@ impl extensions<T> for [T] {
|
|||
and return the results
|
||||
"]
|
||||
fn mapi<U>(f: fn(uint, T) -> U) -> [U] {
|
||||
let mut i = 0u;
|
||||
self.map { |e| i += 1u; f(i - 1u, e) }
|
||||
mapi(self, f)
|
||||
}
|
||||
#[doc = "Returns true if the function returns true for all elements.
|
||||
|
||||
|
|
|
@ -257,10 +257,11 @@ fn finish<T: qq_helper>
|
|||
);
|
||||
let mut rcall = pcall;
|
||||
if (g_len > 0u) {
|
||||
let gather = copy qcx.gather;
|
||||
rcall = mk_call(cx,sp,
|
||||
["syntax", "ext", "qquote", "replace"],
|
||||
[pcall,
|
||||
mk_vec_e(cx,sp, vec::map(copy qcx.gather) {|g|
|
||||
mk_vec_e(cx,sp, vec::map(gather) {|g|
|
||||
mk_call(cx,sp,
|
||||
["syntax", "ext", "qquote", g.constr],
|
||||
[g.e])}),
|
||||
|
|
|
@ -213,7 +213,8 @@ fn run_tests_console(opts: test_opts,
|
|||
|
||||
fn print_failures(st: console_test_state) {
|
||||
st.out.write_line("\nfailures:");
|
||||
let failures = vec::map(copy st.failures) {|test| test.name};
|
||||
let failures = copy st.failures;
|
||||
let failures = vec::map(failures) {|test| test.name};
|
||||
let failures = sort::merge_sort(str::le, failures);
|
||||
for vec::each(failures) {|name|
|
||||
st.out.write_line(#fmt[" %s", name]);
|
||||
|
|
|
@ -4012,7 +4012,8 @@ fn trans_block_cleanups_(bcx: block, cleanup_cx: block, is_lpad: bool) ->
|
|||
let mut bcx = bcx;
|
||||
alt check cleanup_cx.kind {
|
||||
block_scope({cleanups, _}) {
|
||||
vec::riter(copy cleanups) {|cu|
|
||||
let cleanups = copy cleanups;
|
||||
vec::riter(cleanups) {|cu|
|
||||
alt cu {
|
||||
clean(cfn, cleanup_type) | clean_temp(_, cfn, cleanup_type) {
|
||||
// Some types don't need to be cleaned up during
|
||||
|
|
Loading…
Add table
Reference in a new issue