about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2013-06-27 23:58:07 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2013-06-28 00:20:42 +1000
commit4470d14388b1637a1e4862c0650baddf6ed7c430 (patch)
tree738705dec20cdf0c143b6355a48e1143e8234831
parent29b0649a6af8c4821f0d69c544569a9529a68431 (diff)
downloadrust-4470d14388b1637a1e4862c0650baddf6ed7c430.tar.gz
rust-4470d14388b1637a1e4862c0650baddf6ed7c430.zip
Convert vec::truncate to a method.
-rw-r--r--src/libstd/vec.rs27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index f0c81f9c04b..2cc27861207 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -438,20 +438,6 @@ pub fn consume_reverse<T>(mut v: ~[T], f: &fn(uint, v: T)) {
     }
 }
 
-/// Shorten a vector, dropping excess elements.
-pub fn truncate<T>(v: &mut ~[T], newlen: uint) {
-    do as_mut_buf(*v) |p, oldlen| {
-        assert!(newlen <= oldlen);
-        unsafe {
-            // This loop is optimized out for non-drop types.
-            for uint::range(newlen, oldlen) |i| {
-                ptr::replace_ptr(ptr::mut_offset(p, i), intrinsics::uninit());
-            }
-        }
-    }
-    unsafe { raw::set_len(&mut *v, newlen); }
-}
-
 /**
  * Remove consecutive repeated elements from a vector; if the vector is
  * sorted, this removes all duplicates.
@@ -1820,9 +1806,18 @@ impl<T> OwnedVector<T> for ~[T] {
         self.pop()
     }
 
-    #[inline]
+    /// Shorten a vector, dropping excess elements.
     fn truncate(&mut self, newlen: uint) {
-        truncate(self, newlen);
+        do as_mut_buf(*self) |p, oldlen| {
+            assert!(newlen <= oldlen);
+            unsafe {
+                // This loop is optimized out for non-drop types.
+                for uint::range(newlen, oldlen) |i| {
+                    ptr::replace_ptr(ptr::mut_offset(p, i), intrinsics::uninit());
+                }
+            }
+        }
+        unsafe { raw::set_len(self, newlen); }
     }
 
     #[inline]