diff options
| author | Steve Klabnik <steve@steveklabnik.com> | 2015-12-28 15:28:46 -0500 |
|---|---|---|
| committer | Steve Klabnik <steve@steveklabnik.com> | 2015-12-30 12:06:28 -0500 |
| commit | 2cff12e0d6d846c1c2a4c4449ecf7473658573ef (patch) | |
| tree | 5d6ff7aecd329d81b33febfb6884d67e5fa7762d /src/liballoc | |
| parent | 27a1834ce522e3ec7fe4726b1661de16ee30c503 (diff) | |
| download | rust-2cff12e0d6d846c1c2a4c4449ecf7473658573ef.tar.gz rust-2cff12e0d6d846c1c2a4c4449ecf7473658573ef.zip | |
Small refactoring to make this code more clear
This hairy conditional doesn't need to be so. It _does_ need to be a thin pointer, otherwise, it will fail to compile, so let's pull that out into a temporary for future readers of the source. Also, after a discussion with @pnkfelix and @gankro, we don't need these null checks anymore, as zero-on-drop has been gone for a while now.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/arc.rs | 9 | ||||
| -rw-r--r-- | src/liballoc/rc.rs | 10 |
2 files changed, 11 insertions, 8 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 755e44899fc..33712bc5426 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -554,9 +554,9 @@ impl<T: ?Sized> Drop for Arc<T> { // This structure has #[unsafe_no_drop_flag], so this drop glue may run // more than once (but it is guaranteed to be zeroed after the first if // it's run more than once) - let ptr = *self._ptr; - // if ptr.is_null() { return } - if ptr as *mut u8 as usize == 0 || ptr as *mut u8 as usize == mem::POST_DROP_USIZE { + let thin = *self._ptr as *const (); + + if thin as usize == mem::POST_DROP_USIZE { return; } @@ -709,9 +709,10 @@ impl<T: ?Sized> Drop for Weak<T> { /// ``` fn drop(&mut self) { let ptr = *self._ptr; + let thin = ptr as *const (); // see comments above for why this check is here - if ptr as *mut u8 as usize == 0 || ptr as *mut u8 as usize == mem::POST_DROP_USIZE { + if thin as usize == mem::POST_DROP_USIZE { return; } diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 52f035b67bd..b86ddaa167b 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -449,8 +449,9 @@ impl<T: ?Sized> Drop for Rc<T> { fn drop(&mut self) { unsafe { let ptr = *self._ptr; - if !(*(&ptr as *const _ as *const *const ())).is_null() && - ptr as *const () as usize != mem::POST_DROP_USIZE { + let thin = ptr as *const (); + + if thin as usize != mem::POST_DROP_USIZE { self.dec_strong(); if self.strong() == 0 { // destroy the contained object @@ -782,8 +783,9 @@ impl<T: ?Sized> Drop for Weak<T> { fn drop(&mut self) { unsafe { let ptr = *self._ptr; - if !(*(&ptr as *const _ as *const *const ())).is_null() && - ptr as *const () as usize != mem::POST_DROP_USIZE { + let thin = ptr as *const (); + + if thin as usize != mem::POST_DROP_USIZE { self.dec_weak(); // the weak count starts at 1, and will only go to zero if all // the strong pointers have disappeared. |
