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

Function extract_cloned

crates/vm/src/builtins/list.rs:426–450  ·  view source on GitHub ↗
(obj: &PyObject, mut f: F, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

424}
425
426fn extract_cloned<F, R>(obj: &PyObject, mut f: F, vm: &VirtualMachine) -> PyResult<Vec<R>>
427where
428 F: FnMut(PyObjectRef) -> PyResult<R>,
429{
430 use crate::builtins::PyTuple;
431 if let Some(tuple) = obj.downcast_ref_if_exact::<PyTuple>(vm) {
432 tuple.iter().map(|x| f(x.clone())).collect()
433 } else if let Some(list) = obj.downcast_ref_if_exact::<PyList>(vm) {
434 list.borrow_vec().iter().map(|x| f(x.clone())).collect()
435 } else {
436 let iter = obj.to_owned().get_iter(vm)?;
437 let iter = iter.iter::<PyObjectRef>(vm)?;
438 let len = obj
439 .sequence_unchecked()
440 .length_opt(vm)
441 .transpose()?
442 .unwrap_or(0);
443 let mut v = Vec::with_capacity(len);
444 for x in iter {
445 v.push(f(x?)?);
446 }
447 v.shrink_to_fit();
448 Ok(v)
449 }
450}
451
452impl MutObjectSequenceOp for PyList {
453 type Inner = [PyObjectRef];

Callers 3

inplace_concatMethod · 0.85
__iadd__Method · 0.85
_setitemMethod · 0.85

Calls 12

collectMethod · 0.80
borrow_vecMethod · 0.80
get_iterMethod · 0.80
sequence_uncheckedMethod · 0.80
shrink_to_fitMethod · 0.80
fFunction · 0.50
mapMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45
to_ownedMethod · 0.45
length_optMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected