Avoid ptrtoint when checking if a pointer is null

Casting the pointer to an integer requires a ptrtoint, while casting 0
to a pointer is directly folded to a `null` value.
This commit is contained in:
Björn Steinbrink 2015-02-02 21:45:49 +01:00
parent dfc5c0f1e8
commit 52b5150cfd

View File

@ -303,7 +303,7 @@ impl<T> PtrExt for *const T {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn is_null(self) -> bool { self as usize == 0 }
fn is_null(self) -> bool { self == 0 as *const T }
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
@ -330,7 +330,7 @@ impl<T> PtrExt for *mut T {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn is_null(self) -> bool { self as usize == 0 }
fn is_null(self) -> bool { self == 0 as *mut T }
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]