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:
parent
dfc5c0f1e8
commit
52b5150cfd
1 changed files with 2 additions and 2 deletions
|
@ -303,7 +303,7 @@ impl<T> PtrExt for *const T {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[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]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
@ -330,7 +330,7 @@ impl<T> PtrExt for *mut T {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[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]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue