| 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>> { |