Skip to content

Commit 4470d14

Browse files
committed
Convert vec::truncate to a method.
1 parent 29b0649 commit 4470d14

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/libstd/vec.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -438,20 +438,6 @@ pub fn consume_reverse<T>(mut v: ~[T], f: &fn(uint, v: T)) {
438438
}
439439
}
440440

441-
/// Shorten a vector, dropping excess elements.
442-
pub fn truncate<T>(v: &mut ~[T], newlen: uint) {
443-
do as_mut_buf(*v) |p, oldlen| {
444-
assert!(newlen <= oldlen);
445-
unsafe {
446-
// This loop is optimized out for non-drop types.
447-
for uint::range(newlen, oldlen) |i| {
448-
ptr::replace_ptr(ptr::mut_offset(p, i), intrinsics::uninit());
449-
}
450-
}
451-
}
452-
unsafe { raw::set_len(&mut *v, newlen); }
453-
}
454-
455441
/**
456442
* Remove consecutive repeated elements from a vector; if the vector is
457443
* sorted, this removes all duplicates.
@@ -1820,9 +1806,18 @@ impl<T> OwnedVector<T> for ~[T] {
18201806
self.pop()
18211807
}
18221808

1823-
#[inline]
1809+
/// Shorten a vector, dropping excess elements.
18241810
fn truncate(&mut self, newlen: uint) {
1825-
truncate(self, newlen);
1811+
do as_mut_buf(*self) |p, oldlen| {
1812+
assert!(newlen <= oldlen);
1813+
unsafe {
1814+
// This loop is optimized out for non-drop types.
1815+
for uint::range(newlen, oldlen) |i| {
1816+
ptr::replace_ptr(ptr::mut_offset(p, i), intrinsics::uninit());
1817+
}
1818+
}
1819+
}
1820+
unsafe { raw::set_len(self, newlen); }
18261821
}
18271822

18281823
#[inline]

0 commit comments

Comments
 (0)