Skip to content

Commit 4993925

Browse files
authored
Merge pull request #4742 from qingshi163/cmpref
Improve Comparable take zelf as reference
2 parents 11e69ea + e22ff3a commit 4993925

File tree

1 file changed

+13
-36
lines changed

1 file changed

+13
-36
lines changed

vm/src/types/slot.rs

+13-36
Original file line numberDiff line numberDiff line change
@@ -992,58 +992,35 @@ pub trait Comparable: PyPayload {
992992
vm: &VirtualMachine,
993993
) -> PyResult<PyComparisonValue>;
994994

995+
#[inline]
995996
#[pymethod(magic)]
996-
fn eq(
997-
zelf: PyRef<Self>,
998-
other: PyObjectRef,
999-
vm: &VirtualMachine,
1000-
) -> PyResult<PyComparisonValue> {
1001-
Self::cmp(&zelf, &other, PyComparisonOp::Eq, vm)
997+
fn eq(zelf: &Py<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyComparisonValue> {
998+
Self::cmp(zelf, &other, PyComparisonOp::Eq, vm)
1002999
}
10031000
#[inline]
10041001
#[pymethod(magic)]
1005-
fn ne(
1006-
zelf: PyRef<Self>,
1007-
other: PyObjectRef,
1008-
vm: &VirtualMachine,
1009-
) -> PyResult<PyComparisonValue> {
1010-
Self::cmp(&zelf, &other, PyComparisonOp::Ne, vm)
1002+
fn ne(zelf: &Py<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyComparisonValue> {
1003+
Self::cmp(zelf, &other, PyComparisonOp::Ne, vm)
10111004
}
10121005
#[inline]
10131006
#[pymethod(magic)]
1014-
fn lt(
1015-
zelf: PyRef<Self>,
1016-
other: PyObjectRef,
1017-
vm: &VirtualMachine,
1018-
) -> PyResult<PyComparisonValue> {
1019-
Self::cmp(&zelf, &other, PyComparisonOp::Lt, vm)
1007+
fn lt(zelf: &Py<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyComparisonValue> {
1008+
Self::cmp(zelf, &other, PyComparisonOp::Lt, vm)
10201009
}
10211010
#[inline]
10221011
#[pymethod(magic)]
1023-
fn le(
1024-
zelf: PyRef<Self>,
1025-
other: PyObjectRef,
1026-
vm: &VirtualMachine,
1027-
) -> PyResult<PyComparisonValue> {
1028-
Self::cmp(&zelf, &other, PyComparisonOp::Le, vm)
1012+
fn le(zelf: &Py<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyComparisonValue> {
1013+
Self::cmp(zelf, &other, PyComparisonOp::Le, vm)
10291014
}
10301015
#[inline]
10311016
#[pymethod(magic)]
1032-
fn ge(
1033-
zelf: PyRef<Self>,
1034-
other: PyObjectRef,
1035-
vm: &VirtualMachine,
1036-
) -> PyResult<PyComparisonValue> {
1037-
Self::cmp(&zelf, &other, PyComparisonOp::Ge, vm)
1017+
fn ge(zelf: &Py<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyComparisonValue> {
1018+
Self::cmp(zelf, &other, PyComparisonOp::Ge, vm)
10381019
}
10391020
#[inline]
10401021
#[pymethod(magic)]
1041-
fn gt(
1042-
zelf: PyRef<Self>,
1043-
other: PyObjectRef,
1044-
vm: &VirtualMachine,
1045-
) -> PyResult<PyComparisonValue> {
1046-
Self::cmp(&zelf, &other, PyComparisonOp::Gt, vm)
1022+
fn gt(zelf: &Py<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyComparisonValue> {
1023+
Self::cmp(zelf, &other, PyComparisonOp::Gt, vm)
10471024
}
10481025
}
10491026

0 commit comments

Comments
 (0)