diff --git a/vm/src/stdlib/collections.rs b/vm/src/stdlib/collections.rs index 301bbe4be..b9cb755d3 100644 --- a/vm/src/stdlib/collections.rs +++ b/vm/src/stdlib/collections.rs @@ -20,7 +20,7 @@ mod _collections { #[derive(Debug)] struct PyDeque { deque: PyRwLock>, - maxlen: AtomicCell>, + maxlen: Option, } type PyDequeRef = PyRef; @@ -76,7 +76,7 @@ mod _collections { ) -> PyResult> { let py_deque = PyDeque { deque: PyRwLock::default(), - maxlen: AtomicCell::new(maxlen), + maxlen, } .into_ref_with_type(vm, cls)?; if let OptionalArg::Present(iter) = iter { @@ -88,7 +88,7 @@ mod _collections { #[pymethod] fn append(&self, obj: PyObjectRef) { let mut deque = self.borrow_deque_mut(); - if self.maxlen.load() == Some(deque.len()) { + if self.maxlen == Some(deque.len()) { deque.pop_front(); } deque.push_back(obj); @@ -97,7 +97,7 @@ mod _collections { #[pymethod] fn appendleft(&self, obj: PyObjectRef) { let mut deque = self.borrow_deque_mut(); - if self.maxlen.load() == Some(deque.len()) { + if self.maxlen == Some(deque.len()) { deque.pop_back(); } deque.push_front(obj); @@ -112,7 +112,7 @@ mod _collections { fn copy(&self) -> Self { PyDeque { deque: PyRwLock::new(self.borrow_deque().clone()), - maxlen: AtomicCell::new(self.maxlen.load()), + maxlen: self.maxlen.clone(), } } @@ -130,7 +130,7 @@ mod _collections { #[pymethod] fn extend(zelf: PyRef, iter: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> { // TODO: use length_hint here and for extendleft - let max_len = zelf.maxlen.load(); + let max_len = zelf.maxlen; let mut elements: Vec = vm.extract_elements(&iter)?; if let Some(max_len) = max_len { if max_len > elements.len() { @@ -181,7 +181,7 @@ mod _collections { fn insert(&self, idx: i32, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> { let mut deque = self.borrow_deque_mut(); - if self.maxlen.load() == Some(deque.len()) { + if self.maxlen == Some(deque.len()) { return Err(vm.new_index_error("deque already at its maximum size".to_owned())); } @@ -249,7 +249,7 @@ mod _collections { #[pyproperty] fn maxlen(&self) -> Option { - self.maxlen.load() + self.maxlen } #[pymethod(magic)] @@ -287,7 +287,6 @@ mod _collections { .collect::, _>>()?; let maxlen = zelf .maxlen - .load() .map(|maxlen| format!(", maxlen={}", maxlen)) .unwrap_or_default(); format!("deque([{}]{})", elements.into_iter().format(", "), maxlen) @@ -315,14 +314,13 @@ mod _collections { let mul = sequence::seq_mul(&deque, n); let skipped = self .maxlen - .load() .and_then(|maxlen| mul.len().checked_sub(maxlen)) .unwrap_or(0); let deque = mul.skip(skipped).cloned().collect(); PyDeque { deque: PyRwLock::new(deque), - maxlen: AtomicCell::new(self.maxlen.load()), + maxlen: self.maxlen.clone(), } }