@@ -7,8 +7,8 @@ use crate::common::hash::PyHash;
77use crate :: function:: { OptionalArg , PyFuncArgs } ;
88use crate :: obj:: objtype:: PyClass ;
99use crate :: pyobject:: {
10- BorrowValue , IdProtocol , ItemProtocol , PyAttributes , PyClassImpl , PyComparisonValue , PyContext ,
11- PyObject , PyObjectRef , PyResult , PyValue , TryFromObject , TypeProtocol ,
10+ BorrowValue , Either , IdProtocol , ItemProtocol , PyAttributes , PyClassImpl , PyComparisonValue ,
11+ PyContext , PyObject , PyObjectRef , PyResult , PyValue , TryFromObject , TypeProtocol ,
1212} ;
1313use crate :: slots:: PyComparisonOp ;
1414use crate :: vm:: VirtualMachine ;
@@ -44,6 +44,16 @@ impl PyBaseObject {
4444 other : PyObjectRef ,
4545 op : PyComparisonOp ,
4646 vm : & VirtualMachine ,
47+ ) -> PyResult < Either < PyObjectRef , PyComparisonValue > > {
48+ Self :: cmp ( zelf, other, op, vm) . map ( Either :: B )
49+ }
50+
51+ #[ inline( always) ]
52+ fn cmp (
53+ zelf : PyObjectRef ,
54+ other : PyObjectRef ,
55+ op : PyComparisonOp ,
56+ vm : & VirtualMachine ,
4757 ) -> PyResult < PyComparisonValue > {
4858 let res = match op {
4959 PyComparisonOp :: Eq => {
@@ -76,47 +86,47 @@ impl PyBaseObject {
7686 other : PyObjectRef ,
7787 vm : & VirtualMachine ,
7888 ) -> PyResult < PyComparisonValue > {
79- Self :: tp_cmp ( zelf, other, PyComparisonOp :: Eq , vm)
89+ Self :: cmp ( zelf, other, PyComparisonOp :: Eq , vm)
8090 }
8191 #[ pymethod( magic) ]
8292 fn ne (
8393 zelf : PyObjectRef ,
8494 other : PyObjectRef ,
8595 vm : & VirtualMachine ,
8696 ) -> PyResult < PyComparisonValue > {
87- Self :: tp_cmp ( zelf, other, PyComparisonOp :: Ne , vm)
97+ Self :: cmp ( zelf, other, PyComparisonOp :: Ne , vm)
8898 }
8999 #[ pymethod( magic) ]
90100 fn lt (
91101 zelf : PyObjectRef ,
92102 other : PyObjectRef ,
93103 vm : & VirtualMachine ,
94104 ) -> PyResult < PyComparisonValue > {
95- Self :: tp_cmp ( zelf, other, PyComparisonOp :: Lt , vm)
105+ Self :: cmp ( zelf, other, PyComparisonOp :: Lt , vm)
96106 }
97107 #[ pymethod( magic) ]
98108 fn le (
99109 zelf : PyObjectRef ,
100110 other : PyObjectRef ,
101111 vm : & VirtualMachine ,
102112 ) -> PyResult < PyComparisonValue > {
103- Self :: tp_cmp ( zelf, other, PyComparisonOp :: Le , vm)
113+ Self :: cmp ( zelf, other, PyComparisonOp :: Le , vm)
104114 }
105115 #[ pymethod( magic) ]
106116 fn ge (
107117 zelf : PyObjectRef ,
108118 other : PyObjectRef ,
109119 vm : & VirtualMachine ,
110120 ) -> PyResult < PyComparisonValue > {
111- Self :: tp_cmp ( zelf, other, PyComparisonOp :: Ge , vm)
121+ Self :: cmp ( zelf, other, PyComparisonOp :: Ge , vm)
112122 }
113123 #[ pymethod( magic) ]
114124 fn gt (
115125 zelf : PyObjectRef ,
116126 other : PyObjectRef ,
117127 vm : & VirtualMachine ,
118128 ) -> PyResult < PyComparisonValue > {
119- Self :: tp_cmp ( zelf, other, PyComparisonOp :: Gt , vm)
129+ Self :: cmp ( zelf, other, PyComparisonOp :: Gt , vm)
120130 }
121131
122132 #[ pymethod( magic) ]
0 commit comments