提交 8aee5826 编写于 作者: B bors

Auto merge of #30593 - steveklabnik:small_rc_refactoring, r=Gankro

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.

/cc @nrc @SimonSapin @Gankro @durka , who brought this up on IRC
...@@ -555,9 +555,9 @@ fn drop(&mut self) { ...@@ -555,9 +555,9 @@ fn drop(&mut self) {
// This structure has #[unsafe_no_drop_flag], so this drop glue may run // 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 // more than once (but it is guaranteed to be zeroed after the first if
// it's run more than once) // it's run more than once)
let ptr = *self._ptr; let thin = *self._ptr as *const ();
// if ptr.is_null() { return }
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; return;
} }
...@@ -710,9 +710,10 @@ impl<T: ?Sized> Drop for Weak<T> { ...@@ -710,9 +710,10 @@ impl<T: ?Sized> Drop for Weak<T> {
/// ``` /// ```
fn drop(&mut self) { fn drop(&mut self) {
let ptr = *self._ptr; let ptr = *self._ptr;
let thin = ptr as *const ();
// see comments above for why this check is here // 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; return;
} }
......
...@@ -449,8 +449,9 @@ impl<T: ?Sized> Drop for Rc<T> { ...@@ -449,8 +449,9 @@ impl<T: ?Sized> Drop for Rc<T> {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
let ptr = *self._ptr; let ptr = *self._ptr;
if !(*(&ptr as *const _ as *const *const ())).is_null() && let thin = ptr as *const ();
ptr as *const () as usize != mem::POST_DROP_USIZE {
if thin as usize != mem::POST_DROP_USIZE {
self.dec_strong(); self.dec_strong();
if self.strong() == 0 { if self.strong() == 0 {
// destroy the contained object // destroy the contained object
...@@ -782,8 +783,9 @@ impl<T: ?Sized> Drop for Weak<T> { ...@@ -782,8 +783,9 @@ impl<T: ?Sized> Drop for Weak<T> {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
let ptr = *self._ptr; let ptr = *self._ptr;
if !(*(&ptr as *const _ as *const *const ())).is_null() && let thin = ptr as *const ();
ptr as *const () as usize != mem::POST_DROP_USIZE {
if thin as usize != mem::POST_DROP_USIZE {
self.dec_weak(); self.dec_weak();
// the weak count starts at 1, and will only go to zero if all // the weak count starts at 1, and will only go to zero if all
// the strong pointers have disappeared. // the strong pointers have disappeared.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册