MCPcopy Index your code
hub / github.com/RustPython/RustPython / richcompare

Method richcompare

crates/vm/src/iter.rs:19–50  ·  view source on GitHub ↗
(
        self,
        other: impl PyExactSizeIterator<'a>,
        op: PyComparisonOp,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

17 }
18
19 fn richcompare(
20 self,
21 other: impl PyExactSizeIterator<'a>,
22 op: PyComparisonOp,
23 vm: &VirtualMachine,
24 ) -> PyResult<bool> {
25 let less = match op {
26 PyComparisonOp::Eq => return PyExactSizeIterator::eq(self, other, vm),
27 PyComparisonOp::Ne => return PyExactSizeIterator::eq(self, other, vm).map(|eq| !eq),
28 PyComparisonOp::Lt | PyComparisonOp::Le => true,
29 PyComparisonOp::Gt | PyComparisonOp::Ge => false,
30 };
31
32 let lhs = self;
33 let rhs = other;
34 let lhs_len = lhs.len();
35 let rhs_len = rhs.len();
36 for (a, b) in lhs.zip(rhs) {
37 if vm.bool_eq(a, b)? {
38 continue;
39 }
40 let ret = if less {
41 vm.bool_seq_lt(a, b)?
42 } else {
43 vm.bool_seq_gt(a, b)?
44 };
45 if let Some(v) = ret {
46 return Ok(v);
47 }
48 }
49 Ok(op.eval_ord(lhs_len.cmp(&rhs_len)))
50 }
51}
52
53impl<'a, T> PyExactSizeIterator<'a> for T where T: ExactSizeIterator<Item = &'a PyObjectRef> + Sized {}

Callers 5

cmpMethod · 0.80
cmpMethod · 0.80
cmpMethod · 0.80
cmpMethod · 0.80

Implementers 1

iter.rscrates/vm/src/iter.rs

Calls 8

bool_eqMethod · 0.80
bool_seq_ltMethod · 0.80
bool_seq_gtMethod · 0.80
eval_ordMethod · 0.80
eqFunction · 0.50
mapMethod · 0.45
lenMethod · 0.45
cmpMethod · 0.45

Tested by

no test coverage detected