Skip to content

Commit

Permalink
Avoid ptrtoint when checking if a pointer is null
Browse files Browse the repository at this point in the history
Casting the pointer to an integer requires a ptrtoint, while casting 0
to a pointer is directly folded to a `null` value.
  • Loading branch information
dotdash committed Feb 18, 2015
1 parent dfc5c0f commit 52b5150
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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")]
Expand Down

0 comments on commit 52b5150

Please sign in to comment.