@@ -267,17 +267,16 @@ impl<'a> ToCStr for &'a [u8] {
267
267
}
268
268
269
269
unsafe fn to_c_str_unchecked ( & self ) -> CString {
270
- self . as_imm_buf ( |self_buf , self_len| {
271
- let buf = libc:: malloc ( self_len as libc:: size_t + 1 ) as * mut u8 ;
272
- if buf. is_null ( ) {
273
- fail ! ( "failed to allocate memory!" ) ;
274
- }
270
+ let self_len = self . len ( ) ;
271
+ let buf = libc:: malloc ( self_len as libc:: size_t + 1 ) as * mut u8 ;
272
+ if buf. is_null ( ) {
273
+ fail ! ( "failed to allocate memory!" ) ;
274
+ }
275
275
276
- ptr:: copy_memory ( buf, self_buf , self_len) ;
277
- * ptr:: mut_offset ( buf, self_len as int ) = 0 ;
276
+ ptr:: copy_memory ( buf, self . as_ptr ( ) , self_len) ;
277
+ * ptr:: mut_offset ( buf, self_len as int ) = 0 ;
278
278
279
- CString :: new ( buf as * libc:: c_char , true )
280
- } )
279
+ CString :: new ( buf as * libc:: c_char , true )
281
280
}
282
281
283
282
fn with_c_str < T > ( & self , f : |* libc:: c_char | -> T ) -> T {
@@ -296,13 +295,12 @@ unsafe fn with_c_str<T>(v: &[u8], checked: bool, f: |*libc::c_char| -> T) -> T {
296
295
vec:: bytes:: copy_memory ( buf, v) ;
297
296
buf[ v. len ( ) ] = 0 ;
298
297
299
- buf. as_mut_buf ( |buf , _| {
300
- if checked {
301
- check_for_null ( v, buf as * mut libc:: c_char ) ;
302
- }
298
+ let buf = buf . as_mut_ptr ( ) ;
299
+ if checked {
300
+ check_for_null ( v, buf as * mut libc:: c_char ) ;
301
+ }
303
302
304
- f ( buf as * libc:: c_char )
305
- } )
303
+ f ( buf as * libc:: c_char )
306
304
} else if checked {
307
305
v. to_c_str ( ) . with_ref ( f)
308
306
} else {
@@ -575,15 +573,14 @@ mod bench {
575
573
576
574
#[ inline]
577
575
fn check ( s : & str , c_str : * libc:: c_char ) {
578
- s. as_imm_buf ( |s_buf, s_len| {
579
- for i in range ( 0 , s_len) {
580
- unsafe {
581
- assert_eq ! (
582
- * ptr:: offset( s_buf, i as int) as libc:: c_char,
583
- * ptr:: offset( c_str, i as int) ) ;
584
- }
576
+ let s_buf = s. as_ptr ( ) ;
577
+ for i in range ( 0 , s. len ( ) ) {
578
+ unsafe {
579
+ assert_eq ! (
580
+ * ptr:: offset( s_buf, i as int) as libc:: c_char,
581
+ * ptr:: offset( c_str, i as int) ) ;
585
582
}
586
- } )
583
+ }
587
584
}
588
585
589
586
static s_short: & ' static str = "Mary" ;
0 commit comments