Skip to content

Commit cced3c9

Browse files
committed
std: simplify str::as_imm_buf and vec::as_{imm,mut}_buf
1 parent 037a5b1 commit cced3c9

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/libstd/str.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,11 +1957,8 @@ impl<'self> StrSlice<'self> for &'self str {
19571957
*/
19581958
#[inline]
19591959
fn as_imm_buf<T>(&self, f: &fn(*u8, uint) -> T) -> T {
1960-
unsafe {
1961-
let v: *(*u8, uint) = cast::transmute(self);
1962-
let (buf, len) = *v;
1963-
f(buf, len)
1964-
}
1960+
let v: &[u8] = unsafe { cast::transmute(*self) };
1961+
v.as_imm_buf(f)
19651962
}
19661963
19671964
/**

src/libstd/vec.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,7 @@ pub trait MutableVector<'self, T> {
16911691
unsafe fn unsafe_mut_ref(&self, index: uint) -> *mut T;
16921692
unsafe fn unsafe_set(&self, index: uint, val: T);
16931693

1694-
fn as_mut_buf<U>(&self, f: &fn(*mut T, uint) -> U) -> U;
1694+
fn as_mut_buf<U>(self, f: &fn(*mut T, uint) -> U) -> U;
16951695
}
16961696

16971697
impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
@@ -1783,12 +1783,9 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
17831783

17841784
/// Similar to `as_imm_buf` but passing a `*mut T`
17851785
#[inline]
1786-
fn as_mut_buf<U>(&self, f: &fn(*mut T, uint) -> U) -> U {
1787-
unsafe {
1788-
let v : *(*mut T,uint) = transmute(self);
1789-
let (buf,len) = *v;
1790-
f(buf, len / sys::nonzero_size_of::<T>())
1791-
}
1786+
fn as_mut_buf<U>(self, f: &fn(*mut T, uint) -> U) -> U {
1787+
let (buf, len): (*mut T, uint) = unsafe { transmute(self) };
1788+
f(buf, len / sys::nonzero_size_of::<T>())
17921789
}
17931790

17941791
}

0 commit comments

Comments
 (0)