]> git.lizzy.rs Git - rust.git/commitdiff
Convert vec::truncate to a method.
authorHuon Wilson <dbau.pp+github@gmail.com>
Thu, 27 Jun 2013 13:58:07 +0000 (23:58 +1000)
committerHuon Wilson <dbau.pp+github@gmail.com>
Thu, 27 Jun 2013 14:20:42 +0000 (00:20 +1000)
src/libstd/vec.rs

index f0c81f9c04bb6711d5f6631ddebd47a61763c6a5..2cc278612076689d115f1fc98cf8df0e6a6054f3 100644 (file)
@@ -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 @@ fn swap_remove(&mut self, index: uint) -> 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]