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

Method count

crates/vm/src/builtins/memory.rs:752–768  ·  view source on GitHub ↗
(&self, value: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

750
751 #[pymethod]
752 fn count(&self, value: PyObjectRef, vm: &VirtualMachine) -> PyResult<usize> {
753 self.try_not_released(vm)?;
754 if self.desc.ndim() != 1 {
755 return Err(
756 vm.new_not_implemented_error("multi-dimensional sub-views are not implemented")
757 );
758 }
759 let len = self.desc.dim_desc[0].0;
760 let mut count = 0;
761 for i in 0..len {
762 let item = self.getitem_by_idx(i as isize, vm)?;
763 if vm.bool_eq(&item, &value)? {
764 count += 1;
765 }
766 }
767 Ok(count)
768 }
769
770 #[pymethod]
771 fn index(

Callers

nothing calls this directly

Calls 5

try_not_releasedMethod · 0.80
getitem_by_idxMethod · 0.80
bool_eqMethod · 0.80
ErrClass · 0.50
ndimMethod · 0.45

Tested by

no test coverage detected