auto merge of #7996 : erickt/rust/cleanup-strs, r=erickt
This is a cleanup pull request that does: * removes `os::as_c_charp` * moves `str::as_buf` and `str::as_c_str` into `StrSlice` * converts some functions from `StrSlice::as_buf` to `StrSlice::as_c_str` * renames `StrSlice::as_buf` to `StrSlice::as_imm_buf` (and adds `StrSlice::as_mut_buf` to match `vec.rs`. * renames `UniqueStr::as_bytes_with_null_consume` to `UniqueStr::to_bytes` * and other misc cleanups and minor optimizations
This commit is contained in:
@@ -87,6 +87,7 @@ pub fn from_elem<T:Clone>(n_elts: uint, t: T) -> ~[T] {
|
||||
}
|
||||
|
||||
/// Creates a new vector with a capacity of `capacity`
|
||||
#[inline]
|
||||
pub fn with_capacity<T>(capacity: uint) -> ~[T] {
|
||||
unsafe {
|
||||
if contains_managed::<T>() {
|
||||
@@ -1691,7 +1692,7 @@ pub trait MutableVector<'self, T> {
|
||||
unsafe fn unsafe_mut_ref(&self, index: uint) -> *mut T;
|
||||
unsafe fn unsafe_set(&self, index: uint, val: T);
|
||||
|
||||
fn as_mut_buf<U>(&self, f: &fn(*mut T, uint) -> U) -> U;
|
||||
fn as_mut_buf<U>(self, f: &fn(*mut T, uint) -> U) -> U;
|
||||
}
|
||||
|
||||
impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
|
||||
@@ -1783,12 +1784,9 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
|
||||
|
||||
/// Similar to `as_imm_buf` but passing a `*mut T`
|
||||
#[inline]
|
||||
fn as_mut_buf<U>(&self, f: &fn(*mut T, uint) -> U) -> U {
|
||||
unsafe {
|
||||
let v : *(*mut T,uint) = transmute(self);
|
||||
let (buf,len) = *v;
|
||||
f(buf, len / sys::nonzero_size_of::<T>())
|
||||
}
|
||||
fn as_mut_buf<U>(self, f: &fn(*mut T, uint) -> U) -> U {
|
||||
let (buf, len): (*mut T, uint) = unsafe { transmute(self) };
|
||||
f(buf, len / sys::nonzero_size_of::<T>())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user