Auto merge of #117960 - zhiqiangxu:dry, r=workingjubilee
chore: avoid duplicate code in `Weak::inner`
This commit is contained in:
commit
c9d85d67c4
@ -2843,16 +2843,14 @@ pub fn weak_count(&self) -> usize {
|
|||||||
/// (i.e., when this `Weak` was created by `Weak::new`).
|
/// (i.e., when this `Weak` was created by `Weak::new`).
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inner(&self) -> Option<WeakInner<'_>> {
|
fn inner(&self) -> Option<WeakInner<'_>> {
|
||||||
if is_dangling(self.ptr.as_ptr()) {
|
let ptr = self.ptr.as_ptr();
|
||||||
|
if is_dangling(ptr) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
// We are careful to *not* create a reference covering the "data" field, as
|
// We are careful to *not* create a reference covering the "data" field, as
|
||||||
// the field may be mutated concurrently (for example, if the last `Arc`
|
// the field may be mutated concurrently (for example, if the last `Arc`
|
||||||
// is dropped, the data field will be dropped in-place).
|
// is dropped, the data field will be dropped in-place).
|
||||||
Some(unsafe {
|
Some(unsafe { WeakInner { strong: &(*ptr).strong, weak: &(*ptr).weak } })
|
||||||
let ptr = self.ptr.as_ptr();
|
|
||||||
WeakInner { strong: &(*ptr).strong, weak: &(*ptr).weak }
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user