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

Method rfind

crates/stdlib/src/mmap.rs:990–1004  ·  view source on GitHub ↗
(&self, options: FindOptions, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

988
989 #[pymethod]
990 fn rfind(&self, options: FindOptions, vm: &VirtualMachine) -> PyResult<PyInt> {
991 let (start, end) = self.get_find_range(options.clone());
992
993 let sub = &options.sub;
994 // returns start position for empty string
995 if sub.is_empty() {
996 return Ok(PyInt::from(start as isize));
997 }
998
999 let mmap = self.check_valid(vm)?;
1000 let buf = &mmap.as_ref().unwrap().as_slice()[start..end];
1001 let pos = buf.windows(sub.len()).rposition(|window| window == sub);
1002
1003 Ok(pos.map_or(PyInt::from(-1isize), |i| PyInt::from(start + i)))
1004 }
1005
1006 #[pymethod]
1007 fn flush(&self, options: FlushOptions, vm: &VirtualMachine) -> PyResult<()> {

Callers

nothing calls this directly

Calls 8

get_find_rangeMethod · 0.80
check_validMethod · 0.80
cloneMethod · 0.45
is_emptyMethod · 0.45
as_sliceMethod · 0.45
unwrapMethod · 0.45
as_refMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected