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

Method remove_if

crates/vm/src/dict_inner.rs:470–489  ·  view source on GitHub ↗

pred should be VERY CAREFUL about what it does as it is called while the dict's internal mutex is held

(
        &self,
        vm: &VirtualMachine,
        key: &K,
        pred: F,
    )

Source from the content-addressed store, hash-verified

468 /// pred should be VERY CAREFUL about what it does as it is called while
469 /// the dict's internal mutex is held
470 pub(crate) fn remove_if<K, F>(
471 &self,
472 vm: &VirtualMachine,
473 key: &K,
474 pred: F,
475 ) -> PyResult<Option<T>>
476 where
477 K: DictKey + ?Sized,
478 F: Fn(&T) -> PyResult<bool>,
479 {
480 let hash = key.key_hash(vm)?;
481 let removed = loop {
482 let lookup = self.lookup(vm, key, hash, None)?;
483 match self.pop_inner_if(lookup, &pred)? {
484 ControlFlow::Break(entry) => break entry,
485 ControlFlow::Continue(()) => continue,
486 }
487 };
488 Ok(removed.map(|entry| entry.value))
489 }
490
491 pub fn delete_or_insert(&self, vm: &VirtualMachine, key: &PyObject, value: T) -> PyResult<()> {
492 let hash = key.key_hash(vm)?;

Callers 2

delete_ifMethod · 0.80
remove_if_existsMethod · 0.80

Calls 4

key_hashMethod · 0.80
pop_inner_ifMethod · 0.80
lookupMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected