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

Method pop_inner_if

crates/vm/src/dict_inner.rs:738–771  ·  view source on GitHub ↗
(
        &self,
        lookup: LookupResult,
        pred: impl Fn(&T) -> Result<bool, E>,
    )

Source from the content-addressed store, hash-verified

736 }
737
738 fn pop_inner_if<E>(
739 &self,
740 lookup: LookupResult,
741 pred: impl Fn(&T) -> Result<bool, E>,
742 ) -> Result<PopInnerResult<T>, E> {
743 let (entry_index, index_index) = lookup;
744 let Some(entry_index) = entry_index.index() else {
745 return Ok(ControlFlow::Break(None));
746 };
747 let inner = &mut *self.write();
748 let slot = if let Some(slot) = inner.entries.get_mut(entry_index) {
749 slot
750 } else {
751 // The dict was changed since we did lookup. Let's try again.
752 return Ok(ControlFlow::Continue(()));
753 };
754 match slot {
755 Some(entry) if entry.index == index_index => {
756 if !pred(&entry.value)? {
757 return Ok(ControlFlow::Break(None));
758 }
759 }
760 // The dict was changed since we did lookup. Let's try again.
761 _ => return Ok(ControlFlow::Continue(())),
762 }
763 *unsafe {
764 // index_index is result of lookup
765 inner.indices.get_unchecked_mut(index_index)
766 } = IndexEntry::DUMMY;
767 inner.used -= 1;
768 let removed = slot.take();
769 self.bump_version();
770 Ok(ControlFlow::Break(removed))
771 }
772
773 /// Retrieve and delete a key
774 pub fn pop<K: DictKey + ?Sized>(&self, vm: &VirtualMachine, key: &K) -> PyResult<Option<T>> {

Callers 2

remove_ifMethod · 0.80
pop_innerMethod · 0.80

Calls 6

BreakClass · 0.85
get_mutMethod · 0.80
bump_versionMethod · 0.80
indexMethod · 0.45
writeMethod · 0.45
takeMethod · 0.45

Tested by

no test coverage detected