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

Method count

crates/vm/src/protocol/sequence.rs:335–352  ·  view source on GitHub ↗
(&self, target: &PyObject, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

333 }
334
335 pub fn count(&self, target: &PyObject, vm: &VirtualMachine) -> PyResult<usize> {
336 let mut n = 0;
337
338 let iter = self.obj.to_owned().get_iter(vm)?;
339 let iter = iter.iter::<PyObjectRef>(vm)?;
340
341 for elem in iter {
342 let elem = elem?;
343 if vm.bool_eq(&elem, target)? {
344 if n == isize::MAX as usize {
345 return Err(vm.new_overflow_error("index exceeds C integer size"));
346 }
347 n += 1;
348 }
349 }
350
351 Ok(n)
352 }
353
354 pub fn index(&self, target: &PyObject, vm: &VirtualMachine) -> PyResult<usize> {
355 let mut index: isize = -1;

Callers 5

slot_initMethod · 0.45
traverseMethod · 0.45
init_thread_countdownMethod · 0.45
line_number_atFunction · 0.45
check_fstring_literalMethod · 0.45

Calls 4

get_iterMethod · 0.80
bool_eqMethod · 0.80
ErrClass · 0.50
to_ownedMethod · 0.45

Tested by

no test coverage detected