Replace vm._hash to obj.hash

This commit is contained in:
ChJR
2021-10-20 02:29:58 +09:00
parent 0d32e1ae16
commit 83c3644add
2 changed files with 5 additions and 9 deletions

View File

@@ -132,7 +132,11 @@ impl PyObjectRef {
}
pub fn hash(&self, vm: &VirtualMachine) -> PyResult<PyHash> {
vm._hash(self)
let hash = self
.class()
.mro_find_map(|cls| cls.slots.hash.load())
.unwrap(); // hash always exist
hash(self, vm)
}
// const hash_not_implemented: fn(&PyObjectRef, &VirtualMachine) ->PyResult<PyHash> = crate::types::Unhashable::slot_hash;

View File

@@ -1885,14 +1885,6 @@ impl VirtualMachine {
self._cmp(&a, &b, op).map(|res| res.into_pyobject(self))
}
pub fn _hash(&self, obj: &PyObjectRef) -> PyResult<rustpython_common::hash::PyHash> {
let hash = obj
.class()
.mro_find_map(|cls| cls.slots.hash.load())
.unwrap(); // hash always exist
hash(obj, self)
}
pub fn obj_len_opt(&self, obj: &PyObjectRef) -> Option<PyResult<usize>> {
self.get_special_method(obj.clone(), "__len__")
.map(Result::ok)