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

Method _mul

crates/vm/src/vm/vm_ops.rs:461–482  ·  view source on GitHub ↗
(&self, a: &PyObject, b: &PyObject)

Source from the content-addressed store, hash-verified

459 }
460
461 pub fn _mul(&self, a: &PyObject, b: &PyObject) -> PyResult {
462 let result = self.binary_op1(a, b, PyNumberBinaryOp::Multiply)?;
463 if !result.is(&self.ctx.not_implemented) {
464 return Ok(result);
465 }
466 if let Ok(seq_a) = a.try_sequence(self) {
467 let n = b
468 .try_index(self)?
469 .as_bigint()
470 .to_isize()
471 .ok_or_else(|| self.new_overflow_error("repeated bytes are too long"))?;
472 return seq_a.repeat(n, self);
473 } else if let Ok(seq_b) = b.try_sequence(self) {
474 let n = a
475 .try_index(self)?
476 .as_bigint()
477 .to_isize()
478 .ok_or_else(|| self.new_overflow_error("repeated bytes are too long"))?;
479 return seq_b.repeat(n, self);
480 }
481 Err(self.new_unsupported_bin_op_error(a, b, "*"))
482 }
483
484 pub fn _imul(&self, a: &PyObject, b: &PyObject) -> PyResult {
485 let result = self.binary_iop1(

Callers 4

prodFunction · 0.45
sumprodFunction · 0.45
execute_bin_opMethod · 0.45
test_multiply_strFunction · 0.45

Calls 9

binary_op1Method · 0.80
isMethod · 0.80
try_sequenceMethod · 0.80
ok_or_elseMethod · 0.80
as_bigintMethod · 0.80
try_indexMethod · 0.80
ErrClass · 0.50
repeatMethod · 0.45

Tested by 1

test_multiply_strFunction · 0.36