clear up dictdatatype and fix arithmetic overflow

This commit is contained in:
Kangzhi Shi
2021-09-23 10:05:05 +02:00
parent b6fa8670e8
commit 4676dd902e
2 changed files with 2 additions and 29 deletions

View File

@@ -218,7 +218,7 @@ impl SlotIterator for PySequenceIterator {
#[derive(Debug)]
pub struct PyCallableIterator {
sentinel: PyObjectRef,
status: PyRwLock<IterStatus<PyCallable>>,
status: PyRwLock<IterStatus<ArgCallable>>,
}
impl PyValue for PyCallableIterator {

View File

@@ -9,7 +9,6 @@ use crate::common::{
};
use crate::vm::VirtualMachine;
use crate::{IdProtocol, IntoPyObject, PyObjectRef, PyRefExact, PyResult, TypeProtocol};
use crossbeam_utils::atomic::AtomicCell;
use std::fmt;
use std::mem::size_of;
@@ -501,34 +500,8 @@ impl<T: Clone> Dict<T> {
}
}
pub fn next_entry_atomic(&self, position: &AtomicCell<usize>) -> Option<(PyObjectRef, T)> {
let inner = self.read();
loop {
let position_usize = position.fetch_add(1);
let entry = inner.entries.get(position_usize)?;
if let Some(entry) = entry {
break Some((entry.key.clone(), entry.value.clone()));
}
}
}
pub fn next_entry_atomic_reversed(
&self,
position: &AtomicCell<usize>,
) -> Option<(PyObjectRef, T)> {
let inner = self.read();
loop {
let position_usize = position.fetch_add(1);
let position_index = inner.entries.len().checked_sub(position_usize + 1)?;
let entry = inner.entries.get(position_index)?;
if let Some(entry) = entry {
break Some((entry.key.clone(), entry.value.clone()));
}
}
}
pub fn len_from_entry_index(&self, position: EntryIndex) -> usize {
self.read().entries.len() - position
self.read().entries.len().saturating_sub(position)
}
pub fn has_changed_size(&self, old: &DictSize) -> bool {