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

Method specialize_compare_op

crates/vm/src/frame.rs:8735–8777  ·  view source on GitHub ↗
(
        &mut self,
        vm: &VirtualMachine,
        op: bytecode::ComparisonOperator,
        instr_idx: usize,
        cache_base: usize,
    )

Source from the content-addressed store, hash-verified

8733 }
8734
8735 fn specialize_compare_op(
8736 &mut self,
8737 vm: &VirtualMachine,
8738 op: bytecode::ComparisonOperator,
8739 instr_idx: usize,
8740 cache_base: usize,
8741 ) {
8742 if !matches!(
8743 self.code.instructions.read_op(instr_idx),
8744 Instruction::CompareOp { .. }
8745 ) {
8746 return;
8747 }
8748 let b = self.top_value();
8749 let a = self.nth_value(1);
8750
8751 let new_op = if let (Some(a_int), Some(b_int)) = (
8752 a.downcast_ref_if_exact::<PyInt>(vm),
8753 b.downcast_ref_if_exact::<PyInt>(vm),
8754 ) {
8755 if specialization_compact_int_value(a_int, vm).is_some()
8756 && specialization_compact_int_value(b_int, vm).is_some()
8757 {
8758 Some(Instruction::CompareOpInt)
8759 } else {
8760 None
8761 }
8762 } else if a.downcast_ref_if_exact::<PyFloat>(vm).is_some()
8763 && b.downcast_ref_if_exact::<PyFloat>(vm).is_some()
8764 {
8765 Some(Instruction::CompareOpFloat)
8766 } else if a.downcast_ref_if_exact::<PyStr>(vm).is_some()
8767 && b.downcast_ref_if_exact::<PyStr>(vm).is_some()
8768 && (op == bytecode::ComparisonOperator::Equal
8769 || op == bytecode::ComparisonOperator::NotEqual)
8770 {
8771 Some(Instruction::CompareOpStr)
8772 } else {
8773 None
8774 };
8775
8776 self.commit_specialization(instr_idx, cache_base, new_op);
8777 }
8778
8779 /// Recover the ComparisonOperator from the instruction arg byte.
8780 /// `replace_op` preserves the arg byte, so the original op remains accessible.

Callers 1

execute_instructionMethod · 0.80

Calls 5

top_valueMethod · 0.80
nth_valueMethod · 0.80
commit_specializationMethod · 0.80
SomeClass · 0.50

Tested by

no test coverage detected