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

Method execute_compare

crates/vm/src/frame.rs:7263–7296  ·  view source on GitHub ↗
(
        &mut self,
        vm: &VirtualMachine,
        op: bytecode::ComparisonOperator,
    )

Source from the content-addressed store, hash-verified

7261
7262 #[cfg_attr(feature = "flame-it", flame("Frame"))]
7263 fn execute_compare(
7264 &mut self,
7265 vm: &VirtualMachine,
7266 op: bytecode::ComparisonOperator,
7267 ) -> FrameResult {
7268 let b = self.pop_value();
7269 let a = self.pop_value();
7270 let cmp_op: PyComparisonOp = op.into();
7271
7272 // COMPARE_OP_INT: leaf type, cannot recurse — skip rich_compare dispatch
7273 if let (Some(a_int), Some(b_int)) = (
7274 a.downcast_ref_if_exact::<PyInt>(vm),
7275 b.downcast_ref_if_exact::<PyInt>(vm),
7276 ) {
7277 let result = cmp_op.eval_ord(a_int.as_bigint().cmp(b_int.as_bigint()));
7278 self.push_value(vm.ctx.new_bool(result).into());
7279 return Ok(None);
7280 }
7281 // COMPARE_OP_FLOAT: leaf type, cannot recurse — skip rich_compare dispatch.
7282 // Falls through on NaN (partial_cmp returns None) for correct != semantics.
7283 if let (Some(a_f), Some(b_f)) = (
7284 a.downcast_ref_if_exact::<PyFloat>(vm),
7285 b.downcast_ref_if_exact::<PyFloat>(vm),
7286 ) && let Some(ord) = a_f.to_f64().partial_cmp(&b_f.to_f64())
7287 {
7288 let result = cmp_op.eval_ord(ord);
7289 self.push_value(vm.ctx.new_bool(result).into());
7290 return Ok(None);
7291 }
7292
7293 let value = a.rich_compare(b, cmp_op, vm)?;
7294 self.push_value(value);
7295 Ok(None)
7296 }
7297
7298 /// Read a cached descriptor pointer and validate it against the expected
7299 /// type version, using a lock-free double-check pattern:

Callers 1

execute_instructionMethod · 0.80

Calls 8

pop_valueMethod · 0.80
eval_ordMethod · 0.80
as_bigintMethod · 0.80
push_valueMethod · 0.80
to_f64Method · 0.80
rich_compareMethod · 0.80
cmpMethod · 0.45
new_boolMethod · 0.45

Tested by

no test coverage detected