Skip to content

Commit 9be1dc1

Browse files
committed
no more IdProtocol-depending api
1 parent 7edebbf commit 9be1dc1

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

vm/src/builtins/bytearray.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ impl Comparable for PyByteArray {
719719
op: PyComparisonOp,
720720
vm: &VirtualMachine,
721721
) -> PyResult<PyComparisonValue> {
722-
if let Some(res) = op.identical_optimization(&zelf, &other) {
722+
if let Some(res) = op.identical_optimization(zelf, other) {
723723
return Ok(res.into());
724724
}
725725
Ok(zelf.inner().cmp(other, op, vm))

vm/src/pyobjectrc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ impl AsRef<PyObject> for PyObject {
772772

773773
impl IdProtocol for PyObjectRef {
774774
fn get_id(&self) -> usize {
775-
self.ptr.as_ptr() as usize
775+
PyObject::get_id(self)
776776
}
777777
}
778778

vm/src/types/slot.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use crate::{
1111
};
1212
use crossbeam_utils::atomic::AtomicCell;
1313
use num_traits::{Signed, ToPrimitive};
14-
use std::{borrow::Cow, cmp::Ordering};
14+
use std::{
15+
borrow::{Borrow, Cow},
16+
cmp::Ordering,
17+
};
1518

1619
// The corresponding field in CPython is `tp_` prefixed.
1720
// e.g. name -> tp_name
@@ -517,11 +520,8 @@ pub trait GetDescriptor: PyValue {
517520
}
518521

519522
#[inline]
520-
fn _cls_is<T>(cls: &Option<PyObjectRef>, other: &T) -> bool
521-
where
522-
T: IdProtocol,
523-
{
524-
cls.as_ref().map_or(false, |cls| other.is(cls))
523+
fn _cls_is(cls: &Option<PyObjectRef>, other: &impl Borrow<PyObject>) -> bool {
524+
cls.as_ref().map_or(false, |cls| other.borrow().is(cls))
525525
}
526526
}
527527

@@ -711,8 +711,12 @@ impl PyComparisonOp {
711711
/// Returns an appropriate return value for the comparison when a and b are the same object, if an
712712
/// appropriate return value exists.
713713
#[inline]
714-
pub fn identical_optimization(self, a: &impl IdProtocol, b: &impl IdProtocol) -> Option<bool> {
715-
self.map_eq(|| a.is(b))
714+
pub fn identical_optimization(
715+
self,
716+
a: &impl Borrow<PyObject>,
717+
b: &impl Borrow<PyObject>,
718+
) -> Option<bool> {
719+
self.map_eq(|| a.borrow().is(b.borrow()))
716720
}
717721

718722
/// Returns `Some(true)` when self is `Eq` and `f()` returns true. Returns `Some(false)` when self

0 commit comments

Comments
 (0)