mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
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
@ -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")]
|
||||
|
Loading…
Reference in New Issue
Block a user