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

Method cmp

crates/vm/src/builtins/slice.rs:310–350  ·  view source on GitHub ↗
(
        zelf: &Py<Self>,
        other: &PyObject,
        op: PyComparisonOp,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

308
309impl Comparable for PySlice {
310 fn cmp(
311 zelf: &Py<Self>,
312 other: &PyObject,
313 op: PyComparisonOp,
314 vm: &VirtualMachine,
315 ) -> PyResult<PyComparisonValue> {
316 let other = class_or_notimplemented!(Self, other);
317
318 let ret = match op {
319 PyComparisonOp::Lt | PyComparisonOp::Le => None
320 .or_else(|| {
321 vm.bool_seq_lt(zelf.start_ref(vm), other.start_ref(vm))
322 .transpose()
323 })
324 .or_else(|| vm.bool_seq_lt(&zelf.stop, &other.stop).transpose())
325 .or_else(|| {
326 vm.bool_seq_lt(zelf.step_ref(vm), other.step_ref(vm))
327 .transpose()
328 })
329 .unwrap_or_else(|| Ok(op == PyComparisonOp::Le))?,
330 PyComparisonOp::Eq | PyComparisonOp::Ne => {
331 let eq = vm.identical_or_equal(zelf.start_ref(vm), other.start_ref(vm))?
332 && vm.identical_or_equal(&zelf.stop, &other.stop)?
333 && vm.identical_or_equal(zelf.step_ref(vm), other.step_ref(vm))?;
334 if op == PyComparisonOp::Ne { !eq } else { eq }
335 }
336 PyComparisonOp::Gt | PyComparisonOp::Ge => None
337 .or_else(|| {
338 vm.bool_seq_gt(zelf.start_ref(vm), other.start_ref(vm))
339 .transpose()
340 })
341 .or_else(|| vm.bool_seq_gt(&zelf.stop, &other.stop).transpose())
342 .or_else(|| {
343 vm.bool_seq_gt(zelf.step_ref(vm), other.step_ref(vm))
344 .transpose()
345 })
346 .unwrap_or_else(|| Ok(op == PyComparisonOp::Ge))?,
347 };
348
349 Ok(PyComparisonValue::Implemented(ret))
350 }
351}
352
353impl Representable for PySlice {

Callers

nothing calls this directly

Calls 5

bool_seq_ltMethod · 0.80
start_refMethod · 0.80
step_refMethod · 0.80
identical_or_equalMethod · 0.80
bool_seq_gtMethod · 0.80

Tested by

no test coverage detected