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

Method find

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

Source from the content-addressed store, hash-verified

970
971 #[pymethod]
972 fn find(&self, options: FindOptions, vm: &VirtualMachine) -> PyResult<PyInt> {
973 let (start, end) = self.get_find_range(options.clone());
974
975 let sub = &options.sub;
976
977 // returns start position for empty string
978 if sub.is_empty() {
979 return Ok(PyInt::from(start as isize));
980 }
981
982 let mmap = self.check_valid(vm)?;
983 let buf = &mmap.as_ref().unwrap().as_slice()[start..end];
984 let pos = buf.windows(sub.len()).position(|window| window == sub);
985
986 Ok(pos.map_or(PyInt::from(-1isize), |i| PyInt::from(start + i)))
987 }
988
989 #[pymethod]
990 fn rfind(&self, options: FindOptions, vm: &VirtualMachine) -> PyResult<PyInt> {

Callers 12

check_locale_nameFunction · 0.45
get_argvFunction · 0.45
highestMethod · 0.45
faulthandler_fatal_errorFunction · 0.45
_get_proxy_settingsFunction · 0.45
_get_proxiesFunction · 0.45
emit_next_tokenFunction · 0.45
columns_nameMethod · 0.45
hostname_matchesFunction · 0.45
curve_name_to_kx_groupFunction · 0.45

Calls 9

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
positionMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected