@@ -1681,15 +1681,16 @@ impl<T> OwnedVector<T> for ~[T] {
16811681 self . pop ( )
16821682 }
16831683 fn truncate ( & mut self , newlen : uint ) {
1684- self . as_mut_buf ( |p, oldlen| {
1685- assert ! ( newlen <= oldlen) ;
1686- unsafe {
1687- // This loop is optimized out for non-drop types.
1688- for i in range ( newlen, oldlen) {
1689- ptr:: read_and_zero_ptr ( ptr:: mut_offset ( p, i as int ) ) ;
1690- }
1684+ let oldlen = self . len ( ) ;
1685+ assert ! ( newlen <= oldlen) ;
1686+
1687+ unsafe {
1688+ let p = self . as_mut_ptr ( ) ;
1689+ // This loop is optimized out for non-drop types.
1690+ for i in range ( newlen, oldlen) {
1691+ ptr:: read_and_zero_ptr ( p. offset ( i as int ) ) ;
16911692 }
1692- } ) ;
1693+ }
16931694 unsafe { self . set_len ( newlen) ; }
16941695 }
16951696
@@ -2053,24 +2054,19 @@ pub trait MutableVector<'a, T> {
20532054 /// `self` and `src` must not overlap. Fails if `self` is
20542055 /// shorter than `src`.
20552056 unsafe fn copy_memory ( self , src : & [ T ] ) ;
2056-
2057- /// Similar to `as_imm_buf` but passing a `*mut T`
2058- fn as_mut_buf < U > ( self , f : |* mut T , uint| -> U ) -> U ;
20592057}
20602058
20612059impl < ' a , T > MutableVector < ' a , T > for & ' a mut [ T ] {
20622060 #[ inline]
20632061 fn mut_slice ( self , start : uint , end : uint ) -> & ' a mut [ T ] {
20642062 assert ! ( start <= end) ;
20652063 assert ! ( end <= self . len( ) ) ;
2066- self . as_mut_buf ( |p, _len| {
2067- unsafe {
2068- cast:: transmute ( Slice {
2069- data : ptr:: mut_offset ( p, start as int ) as * T ,
2064+ unsafe {
2065+ cast:: transmute ( Slice {
2066+ data : self . as_mut_ptr ( ) . offset ( start as int ) as * T ,
20702067 len : ( end - start)
20712068 } )
2072- }
2073- } )
2069+ }
20742070 }
20752071
20762072 #[ inline]
@@ -2189,17 +2185,9 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] {
21892185
21902186 #[ inline]
21912187 unsafe fn copy_memory ( self , src : & [ T ] ) {
2192- self . as_mut_buf ( |p_dst, len_dst| {
2193- let len_src = src. len ( ) ;
2194- assert ! ( len_dst >= len_src) ;
2195- ptr:: copy_nonoverlapping_memory ( p_dst, src. as_ptr ( ) , len_src)
2196- } )
2197- }
2198-
2199- #[ inline]
2200- fn as_mut_buf < U > ( self , f : |* mut T , uint| -> U ) -> U {
2201- let Slice { data, len } = self . repr ( ) ;
2202- f ( data as * mut T , len)
2188+ let len_src = src. len ( ) ;
2189+ assert ! ( self . len( ) >= len_src) ;
2190+ ptr:: copy_nonoverlapping_memory ( self . as_mut_ptr ( ) , src. as_ptr ( ) , len_src)
22032191 }
22042192}
22052193
@@ -2283,7 +2271,7 @@ pub mod raw {
22832271 pub unsafe fn from_buf_raw < T > ( ptr : * T , elts : uint ) -> ~[ T ] {
22842272 let mut dst = with_capacity ( elts) ;
22852273 dst. set_len ( elts) ;
2286- dst . as_mut_buf ( |p_dst , _len_dst| ptr:: copy_memory ( p_dst , ptr, elts) ) ;
2274+ ptr:: copy_memory ( dst . as_mut_ptr ( ) , ptr, elts) ;
22872275 dst
22882276 }
22892277
@@ -2315,6 +2303,7 @@ pub mod raw {
23152303
23162304/// Operations on `[u8]`.
23172305pub mod bytes {
2306+ use container:: Container ;
23182307 use vec:: MutableVector ;
23192308 use ptr;
23202309
@@ -2327,9 +2316,7 @@ pub mod bytes {
23272316 impl < ' a > MutableByteVector for & ' a mut [ u8 ] {
23282317 #[ inline]
23292318 fn set_memory ( self , value : u8 ) {
2330- self . as_mut_buf ( |p, len| {
2331- unsafe { ptr:: set_memory ( p, value, len) } ;
2332- } )
2319+ unsafe { ptr:: set_memory ( self . as_mut_ptr ( ) , value, self . len ( ) ) } ;
23332320 }
23342321 }
23352322
@@ -2351,9 +2338,7 @@ pub mod bytes {
23512338 let old_len = dst. len ( ) ;
23522339 dst. reserve_additional ( src. len ( ) ) ;
23532340 unsafe {
2354- dst. as_mut_buf ( |p_dst, len_dst| {
2355- ptr:: copy_memory ( p_dst. offset ( len_dst as int ) , src. as_ptr ( ) , src. len ( ) )
2356- } ) ;
2341+ ptr:: copy_memory ( dst. as_mut_ptr ( ) . offset ( old_len as int ) , src. as_ptr ( ) , src. len ( ) ) ;
23572342 dst. set_len ( old_len + src. len ( ) ) ;
23582343 }
23592344 }
@@ -3534,15 +3519,6 @@ mod tests {
35343519 }
35353520 }
35363521
3537- #[ test]
3538- #[ should_fail]
3539- fn test_as_mut_buf_fail ( ) {
3540- let mut v = [ ( ~0 , @0 ) , ( ~0 , @0 ) , ( ~0 , @0 ) , ( ~0 , @0 ) ] ;
3541- v. as_mut_buf ( |_buf, _i| {
3542- fail ! ( )
3543- } )
3544- }
3545-
35463522 #[ test]
35473523 #[ should_fail]
35483524 fn test_copy_memory_oob ( ) {
0 commit comments