Skip to content

Commit c2bb72f

Browse files
committed
PyObjectWeak as type alias
1 parent dc37d3d commit c2bb72f

1 file changed

Lines changed: 12 additions & 40 deletions

File tree

vm/src/pyobjectrc.rs

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ impl WeakRefList {
162162
if let Some(generic_weakref) = inner.generic_weakref {
163163
let generic_weakref = unsafe { generic_weakref.as_ref() };
164164
if generic_weakref.0.ref_count.get() != 0 {
165-
return PyObjectWeak {
166-
weak: generic_weakref.to_owned(),
167-
};
165+
return generic_weakref.to_owned();
168166
}
169167
}
170168
}
@@ -182,7 +180,7 @@ impl WeakRefList {
182180
if is_generic {
183181
inner.generic_weakref = Some(NonNull::from(&*weak));
184182
}
185-
PyObjectWeak { weak }
183+
weak
186184
}
187185

188186
fn clear(&self) {
@@ -258,9 +256,7 @@ impl WeakRefList {
258256
None => return vec![],
259257
};
260258
let mut v = Vec::with_capacity(inner.ref_count - 1);
261-
v.extend(inner.iter().map(|wr| PyObjectWeak {
262-
weak: wr.to_owned(),
263-
}));
259+
v.extend(inner.iter().map(|wr| wr.to_owned()));
264260
v
265261
}
266262
}
@@ -365,6 +361,15 @@ impl Drop for PyWeak {
365361
}
366362
}
367363

364+
pub type PyObjectWeak = PyRef<PyWeak>;
365+
366+
impl PyObjectWeak {
367+
#[inline(always)]
368+
pub fn upgrade(&self) -> Option<PyObjectRef> {
369+
PyWeak::upgrade(self)
370+
}
371+
}
372+
368373
#[derive(Debug)]
369374
struct InstanceDict {
370375
d: PyRwLock<PyDictRef>,
@@ -439,12 +444,6 @@ cfg_if::cfg_if! {
439444
}
440445
}
441446

442-
#[derive(Clone)]
443-
#[repr(transparent)]
444-
pub struct PyObjectWeak {
445-
weak: PyRef<PyWeak>,
446-
}
447-
448447
#[repr(transparent)]
449448
pub struct PyObject(PyInner<Erased>);
450449

@@ -785,27 +784,6 @@ impl<'a, T: PyObjectPayload> From<&'a PyObjectView<T>> for &'a PyObject {
785784
}
786785
}
787786

788-
impl Borrow<PyObject> for PyObjectWeak {
789-
#[inline(always)]
790-
fn borrow(&self) -> &PyObject {
791-
self.weak.as_object()
792-
}
793-
}
794-
795-
impl From<PyObjectWeak> for PyRef<PyWeak> {
796-
#[inline(always)]
797-
fn from(value: PyObjectWeak) -> Self {
798-
value.weak
799-
}
800-
}
801-
802-
impl PyObjectWeak {
803-
#[inline(always)]
804-
pub fn upgrade(&self) -> Option<PyObjectRef> {
805-
self.weak.upgrade()
806-
}
807-
}
808-
809787
impl Drop for PyObjectRef {
810788
#[inline]
811789
fn drop(&mut self) {
@@ -843,12 +821,6 @@ impl fmt::Debug for PyObjectRef {
843821
}
844822
}
845823

846-
impl fmt::Debug for PyObjectWeak {
847-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
848-
write!(f, "(PyWeak)")
849-
}
850-
}
851-
852824
#[repr(transparent)]
853825
pub struct PyObjectView<T: PyObjectPayload>(PyInner<T>);
854826

0 commit comments

Comments
 (0)