Skip to content

Commit 89fad4c

Browse files
committed
---
yaml --- r: 1699 b: refs/heads/master c: 368eb4b h: refs/heads/master i: 1697: a65e19f 1695: 772b44d v: v3
1 parent 1830e5f commit 89fad4c

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 8b82a549bf89f101efc19638357d360a968b1348
2+
refs/heads/master: 368eb4bab615feb99e203eecdcec6d0be02f5b42

trunk/src/lib/_vec.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ native "rust" mod rustrt {
2020
* want to invoke this as vec_alloc[vec[U], U].
2121
*/
2222
fn vec_alloc[T, U](uint n_elts) -> vec[U];
23+
fn vec_alloc_mut[T, U](uint n_elts) -> vec[mutable U];
2324

2425
fn refcount[T](vec[T] v) -> uint;
2526

@@ -30,6 +31,10 @@ fn alloc[T](uint n_elts) -> vec[T] {
3031
ret rustrt.vec_alloc[vec[T], T](n_elts);
3132
}
3233

34+
fn alloc_mut[T](uint n_elts) -> vec[mutable T] {
35+
ret rustrt.vec_alloc_mut[vec[mutable T], T](n_elts);
36+
}
37+
3338
fn refcount[T](vec[T] v) -> uint {
3439
auto r = rustrt.refcount[T](v);
3540
if (r == dbg.const_refcount) {
@@ -52,6 +57,16 @@ fn init_fn[T](&init_op[T] op, uint n_elts) -> vec[T] {
5257
ret v;
5358
}
5459

60+
fn init_fn_mut[T](&init_op[T] op, uint n_elts) -> vec[mutable T] {
61+
let vec[mutable T] v = alloc_mut[T](n_elts);
62+
let uint i = 0u;
63+
while (i < n_elts) {
64+
v += vec(mutable op(i));
65+
i += 1u;
66+
}
67+
ret v;
68+
}
69+
5570
fn init_elt[T](&T t, uint n_elts) -> vec[T] {
5671
/**
5772
* FIXME (issue #81): should be:
@@ -69,6 +84,16 @@ fn init_elt[T](&T t, uint n_elts) -> vec[T] {
6984
ret v;
7085
}
7186

87+
fn init_elt_mut[T](&T t, uint n_elts) -> vec[mutable T] {
88+
let vec[mutable T] v = alloc_mut[T](n_elts);
89+
let uint i = n_elts;
90+
while (i > 0u) {
91+
i -= 1u;
92+
v += vec(mutable t);
93+
}
94+
ret v;
95+
}
96+
7297
fn buf[T](vec[T] v) -> vbuf {
7398
ret rustrt.vec_buf[T](v, 0u);
7499
}

trunk/src/rt/rust_builtin.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ vec_alloc(rust_task *task, type_desc *t, type_desc *elem_t, size_t n_elts)
100100
return vec;
101101
}
102102

103+
extern "C" CDECL rust_vec*
104+
vec_alloc_mut(rust_task *task, type_desc *t, type_desc *elem_t, size_t n_elts)
105+
{
106+
return vec_alloc(task, t, elem_t, n_elts);
107+
}
108+
103109
extern "C" CDECL void *
104110
vec_buf(rust_task *task, type_desc *ty, rust_vec *v, size_t offset)
105111
{

0 commit comments

Comments
 (0)