about summary refs log tree commit diff
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2012-08-01 12:37:13 -0700
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2012-08-01 12:37:13 -0700
commit71927615e0a2cd2d9f96038ba0f403a4d833a2f5 (patch)
treee876aa6f6fa5a46d7e1cb2c68eb764c670f5b4b9
parent357920a0e78160ae1955a61cbf68620cfa788675 (diff)
downloadrust-71927615e0a2cd2d9f96038ba0f403a4d833a2f5.tar.gz
rust-71927615e0a2cd2d9f96038ba0f403a4d833a2f5.zip
core: change vec's ref_set to set_ref, move get_ref to unsafe::get.
-rw-r--r--src/libcore/vec.rs46
1 files changed, 26 insertions, 20 deletions
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs
index 04f10a7f23c..d0cd011ff12 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -189,7 +189,7 @@ pure fn from_fn<T>(n_elts: uint, op: init_op<T>) -> ~[T] {
     let mut v = ~[];
     unchecked{reserve(v, n_elts);}
     let mut i: uint = 0u;
-    while i < n_elts unsafe { ref_set(v, i, op(i)); i += 1u; }
+    while i < n_elts unsafe { unsafe::set(v, i, op(i)); i += 1u; }
     unsafe { unsafe::set_len(v, n_elts); }
     ret v;
 }
@@ -204,8 +204,8 @@ pure fn from_elem<T: copy>(n_elts: uint, t: T) -> ~[T] {
     let mut v = ~[];
     unchecked{reserve(v, n_elts)}
     let mut i: uint = 0u;
-    unsafe { // because ref_set is unsafe
-        while i < n_elts { ref_set(v, i, t); i += 1u; }
+    unsafe { // because unsafe::set is unsafe
+        while i < n_elts { unsafe::set(v, i, t); i += 1u; }
         unsafe { unsafe::set_len(v, n_elts); }
     }
     ret v;
@@ -534,28 +534,12 @@ fn push_slow<T>(&v: ~[const T], +initval: T) {
     unsafe { push_fast(v, initval) }
 }
 
-// Unchecked vector indexing
-#[inline(always)]
-unsafe fn get_ref<T: copy>(v: &[const T], i: uint) -> T {
-    as_buf(v, |p, _len| *ptr::offset(p, i))
-}
-
-#[inline(always)]
-unsafe fn ref_set<T>(v: &[mut T], i: uint, +val: T) {
-    let mut box = some(val);
-    do as_mut_buf(v) |p, _len| {
-        let mut box2 = none;
-        box2 <-> box;
-        rusti::move_val_init(*ptr::mut_offset(p, i), option::unwrap(box2));
-    }
-}
-
 #[inline(always)]
 fn push_all<T: copy>(&v: ~[const T], rhs: &[const T]) {
     reserve(v, v.len() + rhs.len());
 
     for uint::range(0u, rhs.len()) |i| {
-        push(v, unsafe { get_ref(rhs, i) })
+        push(v, unsafe { unsafe::get(rhs, i) })
     }
 }
 
@@ -1612,6 +1596,28 @@ mod unsafe {
     }
 
     /**
+     * Unchecked vector indexing.
+     */
+    #[inline(always)]
+    unsafe fn get<T: copy>(v: &[const T], i: uint) -> T {
+        as_buf(v, |p, _len| *ptr::offset(p, i))
+    }
+
+    /**
+     * Unchecked vector index assignment.
+     */
+    #[inline(always)]
+    unsafe fn set<T>(v: &[mut T], i: uint, +val: T) {
+        let mut box = some(val);
+        do as_mut_buf(v) |p, _len| {
+            let mut box2 = none;
+            box2 <-> box;
+            rusti::move_val_init(*ptr::mut_offset(p, i),
+                                 option::unwrap(box2));
+        }
+    }
+
+    /**
       * Copies data from one vector to another.
       *
       * Copies `count` bytes from `src` to `dst`. The source and destination