Add "mutable?" to _vec in the standard library; fix callers
This commit is contained in:
parent
368eb4bab6
commit
0cf16e77ca
|
@ -35,7 +35,7 @@ fn alloc_mut[T](uint n_elts) -> vec[mutable T] {
|
|||
ret rustrt.vec_alloc_mut[vec[mutable T], T](n_elts);
|
||||
}
|
||||
|
||||
fn refcount[T](vec[T] v) -> uint {
|
||||
fn refcount[T](vec[mutable? T] v) -> uint {
|
||||
auto r = rustrt.refcount[T](v);
|
||||
if (r == dbg.const_refcount) {
|
||||
ret r;
|
||||
|
@ -94,29 +94,29 @@ fn init_elt_mut[T](&T t, uint n_elts) -> vec[mutable T] {
|
|||
ret v;
|
||||
}
|
||||
|
||||
fn buf[T](vec[T] v) -> vbuf {
|
||||
fn buf[T](vec[mutable? T] v) -> vbuf {
|
||||
ret rustrt.vec_buf[T](v, 0u);
|
||||
}
|
||||
|
||||
fn len[T](vec[T] v) -> uint {
|
||||
fn len[T](vec[mutable? T] v) -> uint {
|
||||
ret rustrt.vec_len[T](v);
|
||||
}
|
||||
|
||||
fn len_set[T](vec[T] v, uint n) {
|
||||
fn len_set[T](vec[mutable? T] v, uint n) {
|
||||
rustrt.vec_len_set[T](v, n);
|
||||
}
|
||||
|
||||
fn buf_off[T](vec[T] v, uint offset) -> vbuf {
|
||||
fn buf_off[T](vec[mutable? T] v, uint offset) -> vbuf {
|
||||
check (offset < len[T](v));
|
||||
ret rustrt.vec_buf[T](v, offset);
|
||||
}
|
||||
|
||||
fn print_debug_info[T](vec[T] v) {
|
||||
fn print_debug_info[T](vec[mutable? T] v) {
|
||||
rustrt.vec_print_debug_info[T](v);
|
||||
}
|
||||
|
||||
// Returns elements from [start..end) from v.
|
||||
fn slice[T](vec[T] v, uint start, uint end) -> vec[T] {
|
||||
fn slice[T](vec[mutable? T] v, uint start, uint end) -> vec[T] {
|
||||
check (start <= end);
|
||||
check (end <= len[T](v));
|
||||
auto result = alloc[T](end - start);
|
||||
|
@ -128,7 +128,7 @@ fn slice[T](vec[T] v, uint start, uint end) -> vec[T] {
|
|||
ret result;
|
||||
}
|
||||
|
||||
fn shift[T](&mutable vec[T] v) -> T {
|
||||
fn shift[T](&mutable vec[mutable? T] v) -> T {
|
||||
auto ln = len[T](v);
|
||||
check(ln > 0u);
|
||||
auto e = v.(0);
|
||||
|
@ -136,7 +136,7 @@ fn shift[T](&mutable vec[T] v) -> T {
|
|||
ret e;
|
||||
}
|
||||
|
||||
fn pop[T](&mutable vec[T] v) -> T {
|
||||
fn pop[T](&mutable vec[mutable? T] v) -> T {
|
||||
auto ln = len[T](v);
|
||||
check(ln > 0u);
|
||||
ln -= 1u;
|
||||
|
@ -145,18 +145,18 @@ fn pop[T](&mutable vec[T] v) -> T {
|
|||
ret e;
|
||||
}
|
||||
|
||||
fn push[T](&mutable vec[T] v, &T t) {
|
||||
fn push[T](&mutable vec[mutable? T] v, &T t) {
|
||||
v += vec(t);
|
||||
}
|
||||
|
||||
fn unshift[T](&mutable vec[T] v, &T t) {
|
||||
fn unshift[T](&mutable vec[mutable? T] v, &T t) {
|
||||
auto res = alloc[T](len[T](v) + 1u);
|
||||
res += vec(t);
|
||||
res += v;
|
||||
v = res;
|
||||
}
|
||||
|
||||
fn grow[T](&mutable vec[T] v, int n, &T initval) {
|
||||
fn grow[T](&mutable vec[mutable? T] v, int n, &T initval) {
|
||||
let int i = n;
|
||||
while (i > 0) {
|
||||
i -= 1;
|
||||
|
@ -164,7 +164,7 @@ fn grow[T](&mutable vec[T] v, int n, &T initval) {
|
|||
}
|
||||
}
|
||||
|
||||
fn map[T, U](&option.operator[T,U] f, &vec[T] v) -> vec[U] {
|
||||
fn map[T, U](&option.operator[T,U] f, &vec[mutable? T] v) -> vec[U] {
|
||||
let vec[U] u = alloc[U](len[T](v));
|
||||
for (T ve in v) {
|
||||
u += vec(f(ve));
|
||||
|
@ -172,7 +172,8 @@ fn map[T, U](&option.operator[T,U] f, &vec[T] v) -> vec[U] {
|
|||
ret u;
|
||||
}
|
||||
|
||||
fn map2[T,U,V](&operator2[T,U,V] f, &vec[T] v0, &vec[U] v1) -> vec[V] {
|
||||
fn map2[T,U,V](&operator2[T,U,V] f, &vec[mutable? T] v0, &vec[mutable? U] v1)
|
||||
-> vec[V] {
|
||||
auto v0_len = len[T](v0);
|
||||
if (v0_len != len[U](v1)) {
|
||||
fail;
|
||||
|
|
|
@ -21,7 +21,7 @@ fn create(uint nbits, bool init) -> t {
|
|||
elt = 0u;
|
||||
}
|
||||
|
||||
auto storage = _vec.init_elt[mutable uint](elt, nbits / uint_bits() + 1u);
|
||||
auto storage = _vec.init_elt_mut[uint](elt, nbits / uint_bits() + 1u);
|
||||
ret rec(storage = storage, nbits = nbits);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
|
|||
}
|
||||
|
||||
fn make_buckets[K, V](uint nbkts) -> vec[mutable bucket[K, V]] {
|
||||
ret _vec.init_elt[mutable bucket[K, V]](nil[K, V], nbkts);
|
||||
ret _vec.init_elt_mut[bucket[K, V]](nil[K, V], nbkts);
|
||||
}
|
||||
|
||||
// Derive two hash functions from the one given by taking the upper
|
||||
|
|
|
@ -73,7 +73,7 @@ fn mk_sha1() -> sha1 {
|
|||
0xCA62C1D6u32);
|
||||
|
||||
let int t; // Loop counter
|
||||
let vec[mutable u32] w = _vec.init_elt[mutable u32](0u32, 80u);
|
||||
let vec[mutable u32] w = _vec.init_elt_mut[u32](0u32, 80u);
|
||||
|
||||
// Initialize the first 16 words of the vector w
|
||||
t = 0;
|
||||
|
@ -261,10 +261,10 @@ fn mk_sha1() -> sha1 {
|
|||
}
|
||||
}
|
||||
|
||||
auto st = rec(h = _vec.init_elt[mutable u32](0u32, digest_buf_len),
|
||||
auto st = rec(h = _vec.init_elt_mut[u32](0u32, digest_buf_len),
|
||||
mutable len_low = 0u32,
|
||||
mutable len_high = 0u32,
|
||||
msg_block = _vec.init_elt[mutable u8](0u8, msg_block_len),
|
||||
msg_block = _vec.init_elt_mut[u8](0u8, msg_block_len),
|
||||
mutable msg_block_idx = 0u,
|
||||
mutable computed = false);
|
||||
auto sh = sha1(st);
|
||||
|
|
Loading…
Reference in New Issue