about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-03-18 13:53:49 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-03-18 13:53:49 -0700
commit368eb4bab615feb99e203eecdcec6d0be02f5b42 (patch)
tree4c6349efdd41baf1caa8d1a774166f0f6b5372b0 /src
parent8b82a549bf89f101efc19638357d360a968b1348 (diff)
downloadrust-368eb4bab615feb99e203eecdcec6d0be02f5b42.tar.gz
rust-368eb4bab615feb99e203eecdcec6d0be02f5b42.zip
Add some mutable variants of vector functions to the standard library
Diffstat (limited to 'src')
-rw-r--r--src/lib/_vec.rs25
-rw-r--r--src/rt/rust_builtin.cpp6
2 files changed, 31 insertions, 0 deletions
diff --git a/src/lib/_vec.rs b/src/lib/_vec.rs
index 80cd242d2c8..ce052283982 100644
--- a/src/lib/_vec.rs
+++ b/src/lib/_vec.rs
@@ -20,6 +20,7 @@ native "rust" mod rustrt {
      * want to invoke this as vec_alloc[vec[U], U].
      */
     fn vec_alloc[T, U](uint n_elts) -> vec[U];
+    fn vec_alloc_mut[T, U](uint n_elts) -> vec[mutable U];
 
     fn refcount[T](vec[T] v) -> uint;
 
@@ -30,6 +31,10 @@ fn alloc[T](uint n_elts) -> vec[T] {
     ret rustrt.vec_alloc[vec[T], T](n_elts);
 }
 
+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 {
     auto r = rustrt.refcount[T](v);
     if (r == dbg.const_refcount) {
@@ -52,6 +57,16 @@ fn init_fn[T](&init_op[T] op, uint n_elts) -> vec[T] {
     ret v;
 }
 
+fn init_fn_mut[T](&init_op[T] op, uint n_elts) -> vec[mutable T] {
+    let vec[mutable T] v = alloc_mut[T](n_elts);
+    let uint i = 0u;
+    while (i < n_elts) {
+        v += vec(mutable op(i));
+        i += 1u;
+    }
+    ret v;
+}
+
 fn init_elt[T](&T t, uint n_elts) -> vec[T] {
     /**
      * FIXME (issue #81): should be:
@@ -69,6 +84,16 @@ fn init_elt[T](&T t, uint n_elts) -> vec[T] {
     ret v;
 }
 
+fn init_elt_mut[T](&T t, uint n_elts) -> vec[mutable T] {
+    let vec[mutable T] v = alloc_mut[T](n_elts);
+    let uint i = n_elts;
+    while (i > 0u) {
+        i -= 1u;
+        v += vec(mutable t);
+    }
+    ret v;
+}
+
 fn buf[T](vec[T] v) -> vbuf {
     ret rustrt.vec_buf[T](v, 0u);
 }
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index 1f17fc8c075..1d8f8ba82aa 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -100,6 +100,12 @@ vec_alloc(rust_task *task, type_desc *t, type_desc *elem_t, size_t n_elts)
     return vec;
 }
 
+extern "C" CDECL rust_vec*
+vec_alloc_mut(rust_task *task, type_desc *t, type_desc *elem_t, size_t n_elts)
+{
+    return vec_alloc(task, t, elem_t, n_elts);
+}
+
 extern "C" CDECL void *
 vec_buf(rust_task *task, type_desc *ty, rust_vec *v, size_t offset)
 {