Skip to content

Commit 81581a9

Browse files
committed
first_in_mro -> mro_find_map
1 parent cd61824 commit 81581a9

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

vm/src/obj/objobject.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ impl PyBaseObject {
6666
}
6767
PyComparisonOp::Ne => {
6868
let cmp = zelf
69-
.class()
70-
.first_in_mro(|cls| cls.slots.cmp.load())
69+
.lease_class()
70+
.mro_find_map(|cls| cls.slots.cmp.load())
7171
.unwrap();
7272
let value = match cmp(zelf, other, PyComparisonOp::Eq, vm)? {
7373
Either::A(obj) => PyArithmaticValue::from_object(vm, obj)

vm/src/obj/objtype.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl PyType {
7878
std::iter::once(self).chain(self.mro.iter().map(|cls| cls.deref()))
7979
}
8080

81-
pub(crate) fn first_in_mro<F, R>(&self, f: F) -> Option<R>
81+
pub(crate) fn mro_find_map<F, R>(&self, f: F) -> Option<R>
8282
where
8383
F: Fn(&Self) -> Option<R>,
8484
{
@@ -515,7 +515,7 @@ impl SlotGetattro for PyType {
515515
let attr_class = attr.lease_class();
516516
if attr_class.has_attr("__set__") {
517517
if let Some(ref descr_get) =
518-
PyLease::into_pyref(attr_class).first_in_mro(|cls| cls.slots.descr_get.load())
518+
attr_class.mro_find_map(|cls| cls.slots.descr_get.load())
519519
{
520520
let mcl = PyLease::into_pyref(mcl).into_object();
521521
return descr_get(attr.clone(), Some(zelf.into_object()), Some(mcl), vm);
@@ -526,8 +526,10 @@ impl SlotGetattro for PyType {
526526
let zelf_attr = zelf.get_attr(name);
527527

528528
if let Some(ref attr) = zelf_attr {
529-
let attr_class = attr.class();
530-
if let Some(descr_get) = attr_class.first_in_mro(|cls| cls.slots.descr_get.load()) {
529+
if let Some(descr_get) = attr
530+
.lease_class()
531+
.mro_find_map(|cls| cls.slots.descr_get.load())
532+
{
531533
drop(mcl);
532534
return descr_get(attr.clone(), None, Some(zelf.into_object()), vm);
533535
}

vm/src/pyobjectrc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ where
146146

147147
// CPython-compatible drop implementation
148148
let zelf = Self::into_ref(self.clone());
149-
if let Some(del_slot) = zelf.class().first_in_mro(|cls| cls.slots.del.load()) {
149+
if let Some(del_slot) = zelf.lease_class().mro_find_map(|cls| cls.slots.del.load()) {
150150
crate::vm::thread::with_vm(&zelf, |vm| {
151151
if let Err(e) = del_slot(&zelf, vm) {
152152
// exception in del will be ignored but printed

vm/src/vm.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -880,10 +880,10 @@ impl VirtualMachine {
880880
obj: Option<PyObjectRef>,
881881
cls: Option<PyObjectRef>,
882882
) -> Option<PyResult> {
883-
descr
884-
.class()
885-
.first_in_mro(|cls| cls.slots.descr_get.load())
886-
.map(|descr_get| descr_get(descr, obj, cls, self))
883+
let descr_get = descr
884+
.lease_class()
885+
.mro_find_map(|cls| cls.slots.descr_get.load());
886+
descr_get.map(|descr_get| descr_get(descr, obj, cls, self))
887887
}
888888

889889
pub fn call_get_descriptor(&self, descr: PyObjectRef, obj: PyObjectRef) -> Option<PyResult> {
@@ -915,7 +915,9 @@ impl VirtualMachine {
915915

916916
fn _invoke(&self, callable: &PyObjectRef, args: PyFuncArgs) -> PyResult {
917917
vm_trace!("Invoke: {:?} {:?}", callable, args);
918-
let slot_call = callable.class().first_in_mro(|cls| cls.slots.call.load());
918+
let slot_call = callable
919+
.lease_class()
920+
.mro_find_map(|cls| cls.slots.call.load());
919921
match slot_call {
920922
Some(slot_call) => {
921923
self.trace_event(TraceEvent::Call)?;
@@ -1009,8 +1011,8 @@ impl VirtualMachine {
10091011
let attr_name = attr_name.try_into_ref(self)?;
10101012
vm_trace!("vm.__getattribute__: {:?} {:?}", obj, attr_name);
10111013
let getattro = obj
1012-
.class()
1013-
.first_in_mro(|cls| cls.slots.getattro.load())
1014+
.lease_class()
1015+
.mro_find_map(|cls| cls.slots.getattro.load())
10141016
.unwrap();
10151017
getattro(obj, attr_name, self)
10161018
}
@@ -1153,8 +1155,8 @@ impl VirtualMachine {
11531155
}
11541156

11551157
pub fn is_callable(&self, obj: &PyObjectRef) -> bool {
1156-
obj.class()
1157-
.first_in_mro(|cls| cls.slots.call.load())
1158+
obj.lease_class()
1159+
.mro_find_map(|cls| cls.slots.call.load())
11581160
.is_some()
11591161
}
11601162

@@ -1437,8 +1439,8 @@ impl VirtualMachine {
14371439

14381440
let call_cmp = |obj: &PyObjectRef, other, op| {
14391441
let cmp = obj
1440-
.class()
1441-
.first_in_mro(|cls| cls.slots.cmp.load())
1442+
.lease_class()
1443+
.mro_find_map(|cls| cls.slots.cmp.load())
14421444
.unwrap();
14431445
Ok(match cmp(obj, other, op, self)? {
14441446
Either::A(obj) => PyArithmaticValue::from_object(self, obj).map(Either::A),
@@ -1489,8 +1491,8 @@ impl VirtualMachine {
14891491

14901492
pub fn _hash(&self, obj: &PyObjectRef) -> PyResult<rustpython_common::hash::PyHash> {
14911493
let hash = obj
1492-
.class()
1493-
.first_in_mro(|cls| cls.slots.hash.load())
1494+
.lease_class()
1495+
.mro_find_map(|cls| cls.slots.hash.load())
14941496
.unwrap(); // hash always exist
14951497
hash(&obj, self)
14961498
}

0 commit comments

Comments
 (0)