about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBjörn Steinbrink <bsteinbr@gmail.com>2015-02-02 21:45:49 +0100
committerBjörn Steinbrink <bsteinbr@gmail.com>2015-02-18 14:04:46 +0100
commit52b5150cfd3dfcdf518675e9073f03e061a63a53 (patch)
treef151c225b58184958d90227f805e383903f0db91
parentdfc5c0f1e8799f47f9033bdcc8a7cd8a217620a5 (diff)
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.
-rw-r--r--src/libcore/ptr.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index 072c60c7036..2779e67c743 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -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")]