@@ -72,11 +72,11 @@ pub unsafe fn position<T>(buf: *T, f: &fn(&T) -> bool) -> uint {
72
72
73
73
/// Create an unsafe null pointer
74
74
#[ inline( always) ]
75
- pub fn null < T > ( ) -> * T { unsafe { cast :: transmute ( 0 u ) } }
75
+ pub fn null < T > ( ) -> * T { 0 as * T }
76
76
77
77
/// Create an unsafe mutable null pointer
78
78
#[ inline( always) ]
79
- pub fn mut_null < T > ( ) -> * mut T { unsafe { cast :: transmute ( 0 u ) } }
79
+ pub fn mut_null < T > ( ) -> * mut T { 0 as * mut T }
80
80
81
81
/// Returns true if the pointer is equal to the null pointer.
82
82
#[ inline( always) ]
@@ -237,48 +237,28 @@ pub unsafe fn replace_ptr<T>(dest: *mut T, mut src: T) -> T {
237
237
src
238
238
}
239
239
240
- /**
241
- Transform a region pointer - &T - to an unsafe pointer - *T.
242
- This is safe, but is implemented with an unsafe block due to
243
- transmute.
244
- */
240
+ /// Transform a region pointer - &T - to an unsafe pointer - *T.
245
241
#[ inline( always) ]
246
242
pub fn to_unsafe_ptr < T > ( thing : & T ) -> * T {
247
- unsafe { cast :: transmute ( thing) }
243
+ thing as * T
248
244
}
249
245
250
- /**
251
- Transform a const region pointer - &const T - to a const unsafe pointer -
252
- *const T. This is safe, but is implemented with an unsafe block due to
253
- transmute.
254
- */
246
+ /// Transform a const region pointer - &const T - to a const unsafe pointer - *const T.
255
247
#[ inline( always) ]
256
248
pub fn to_const_unsafe_ptr < T > ( thing : & const T ) -> * const T {
257
- unsafe { cast :: transmute ( thing ) }
249
+ thing as * const T
258
250
}
259
251
260
- /**
261
- Transform a mutable region pointer - &mut T - to a mutable unsafe pointer -
262
- *mut T. This is safe, but is implemented with an unsafe block due to
263
- transmute.
264
- */
252
+ /// Transform a mutable region pointer - &mut T - to a mutable unsafe pointer - *mut T.
265
253
#[ inline( always) ]
266
254
pub fn to_mut_unsafe_ptr < T > ( thing : & mut T ) -> * mut T {
267
- unsafe { cast :: transmute ( thing ) }
255
+ thing as * mut T
268
256
}
269
257
270
- /**
271
- Cast a region pointer - &T - to a uint.
272
- This is safe, but is implemented with an unsafe block due to
273
- transmute.
274
-
275
- (I couldn't think of a cutesy name for this one.)
276
- */
258
+ /// Cast a region pointer - &T - to a uint.
277
259
#[ inline( always) ]
278
260
pub fn to_uint < T > ( thing : & T ) -> uint {
279
- unsafe {
280
- cast:: transmute ( thing)
281
- }
261
+ thing as * T as uint
282
262
}
283
263
284
264
/// Determine if two borrowed pointers point to the same thing.
@@ -404,50 +384,30 @@ impl<T> Ptr<T> for *mut T {
404
384
impl < T > Eq for * const T {
405
385
#[ inline( always) ]
406
386
fn eq ( & self , other : & * const T ) -> bool {
407
- unsafe {
408
- let a: uint = cast:: transmute ( * self ) ;
409
- let b: uint = cast:: transmute ( * other) ;
410
- return a == b;
411
- }
387
+ ( * self as uint ) == ( * other as uint )
412
388
}
413
389
#[ inline( always) ]
414
- fn ne ( & self , other : & * const T ) -> bool { !( * self ) . eq ( other) }
390
+ fn ne ( & self , other : & * const T ) -> bool { !self . eq ( other) }
415
391
}
416
392
417
393
// Comparison for pointers
418
394
#[ cfg( not( test) ) ]
419
395
impl < T > Ord for * const T {
420
396
#[ inline( always) ]
421
397
fn lt ( & self , other : & * const T ) -> bool {
422
- unsafe {
423
- let a: uint = cast:: transmute ( * self ) ;
424
- let b: uint = cast:: transmute ( * other) ;
425
- return a < b;
426
- }
398
+ ( * self as uint ) < ( * other as uint )
427
399
}
428
400
#[ inline( always) ]
429
401
fn le ( & self , other : & * const T ) -> bool {
430
- unsafe {
431
- let a: uint = cast:: transmute ( * self ) ;
432
- let b: uint = cast:: transmute ( * other) ;
433
- return a <= b;
434
- }
402
+ ( * self as uint ) <= ( * other as uint )
435
403
}
436
404
#[ inline( always) ]
437
405
fn ge ( & self , other : & * const T ) -> bool {
438
- unsafe {
439
- let a: uint = cast:: transmute ( * self ) ;
440
- let b: uint = cast:: transmute ( * other) ;
441
- return a >= b;
442
- }
406
+ ( * self as uint ) >= ( * other as uint )
443
407
}
444
408
#[ inline( always) ]
445
409
fn gt ( & self , other : & * const T ) -> bool {
446
- unsafe {
447
- let a: uint = cast:: transmute ( * self ) ;
448
- let b: uint = cast:: transmute ( * other) ;
449
- return a > b;
450
- }
410
+ ( * self as uint ) > ( * other as uint )
451
411
}
452
412
}
453
413
@@ -456,11 +416,11 @@ impl<T> Ord for *const T {
456
416
impl < ' self , T : Eq > Eq for & ' self T {
457
417
#[ inline( always) ]
458
418
fn eq ( & self , other : & & ' self T ) -> bool {
459
- return * ( * self ) == * ( * other) ;
419
+ * ( * self ) == * ( * other)
460
420
}
461
421
#[ inline( always) ]
462
422
fn ne ( & self , other : & & ' self T ) -> bool {
463
- return * ( * self ) != * ( * other) ;
423
+ * ( * self ) != * ( * other)
464
424
}
465
425
}
466
426
0 commit comments