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

Method count

crates/vm/src/builtins/range.rs:405–418  ·  view source on GitHub ↗
(&self, item: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

403
404 #[pymethod]
405 fn count(&self, item: PyObjectRef, vm: &VirtualMachine) -> PyResult<usize> {
406 if let Ok(int) = item.clone().downcast::<PyInt>() {
407 let count = if self.index_of(int.as_bigint()).is_some() {
408 1
409 } else {
410 0
411 };
412 Ok(count)
413 } else {
414 // Dealing with classes who might compare equal with ints in their
415 // __eq__, slow search.
416 iter_search(self.as_object(), &item, SearchType::Count, vm)
417 }
418 }
419}
420
421impl PyRange {

Callers

nothing calls this directly

Calls 5

iter_searchFunction · 0.85
index_ofMethod · 0.80
as_bigintMethod · 0.80
cloneMethod · 0.45
as_objectMethod · 0.45

Tested by

no test coverage detected