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

Method specialize_unpack_sequence

crates/vm/src/frame.rs:9089–9122  ·  view source on GitHub ↗
(
        &mut self,
        vm: &VirtualMachine,
        expected_count: u32,
        instr_idx: usize,
        cache_base: usize,
    )

Source from the content-addressed store, hash-verified

9087 }
9088
9089 fn specialize_unpack_sequence(
9090 &mut self,
9091 vm: &VirtualMachine,
9092 expected_count: u32,
9093 instr_idx: usize,
9094 cache_base: usize,
9095 ) {
9096 if !matches!(
9097 self.code.instructions.read_op(instr_idx),
9098 Instruction::UnpackSequence { .. }
9099 ) {
9100 return;
9101 }
9102 let obj = self.top_value();
9103 let new_op = if let Some(tuple) = obj.downcast_ref_if_exact::<PyTuple>(vm) {
9104 if tuple.len() != expected_count as usize {
9105 None
9106 } else if expected_count == 2 {
9107 Some(Instruction::UnpackSequenceTwoTuple)
9108 } else {
9109 Some(Instruction::UnpackSequenceTuple)
9110 }
9111 } else if let Some(list) = obj.downcast_ref_if_exact::<PyList>(vm) {
9112 if list.borrow_vec().len() == expected_count as usize {
9113 Some(Instruction::UnpackSequenceList)
9114 } else {
9115 None
9116 }
9117 } else {
9118 None
9119 };
9120
9121 self.commit_specialization(instr_idx, cache_base, new_op);
9122 }
9123
9124 fn specialize_store_attr(
9125 &mut self,

Callers 1

execute_instructionMethod · 0.80

Calls 5

top_valueMethod · 0.80
borrow_vecMethod · 0.80
commit_specializationMethod · 0.80
SomeClass · 0.50
lenMethod · 0.45

Tested by

no test coverage detected