Use borrowed SimpleSeqDeque
@@ -59,9 +59,9 @@ mod _collections {
}
}
- struct SimpleSeqDeque(VecDeque<PyObjectRef>);
+ struct SimpleSeqDeque<'a>(PyRwLockReadGuard<'a, VecDeque<PyObjectRef>>);
- impl sequence::SimpleSeq for SimpleSeqDeque {
+ impl sequence::SimpleSeq for SimpleSeqDeque<'_> {
fn len(&self) -> usize {
self.0.len()
}
@@ -71,24 +71,12 @@ mod _collections {
}
}
- impl From<VecDeque<PyObjectRef>> for SimpleSeqDeque {
- fn from(deque: VecDeque<PyObjectRef>) -> Self {
+ impl<'a> From<PyRwLockReadGuard<'a, VecDeque<PyObjectRef>>> for SimpleSeqDeque<'a> {
+ fn from(deque: PyRwLockReadGuard<'a, VecDeque<PyObjectRef>>) -> Self {
Self(deque)
}
}
- impl From<PyRwLockReadGuard<'_, VecDeque<PyObjectRef>>> for SimpleSeqDeque {
- fn from(deque: PyRwLockReadGuard<'_, VecDeque<PyObjectRef>>) -> Self {
- Self(deque.clone())
- }
- }
-
- impl From<PyRwLockWriteGuard<'_, VecDeque<PyObjectRef>>> for SimpleSeqDeque {
- fn from(deque: PyRwLockWriteGuard<'_, VecDeque<PyObjectRef>>) -> Self {
- Self(deque.clone())
- }
- }
-
#[pyimpl(flags(BASETYPE), with(Comparable, Hashable, Iterable))]
impl PyDeque {
#[pyslot]
@@ -485,16 +473,17 @@ mod _collections {
#[pymethod(magic)]
fn imul(zelf: PyRef<Self>, value: isize, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
- let mut deque = zelf.borrow_deque_mut();
- let seq: SimpleSeqDeque = deque.clone().into();
- let mul = sequence::seq_mul(vm, &seq, value)?;
-
+ let mut new_deque: VecDeque<PyObjectRef> = {
+ let deque: SimpleSeqDeque = zelf.borrow_deque().into();
+ let mul = sequence::seq_mul(vm, &deque, value)?;
let skipped = zelf
.maxlen
.and_then(|maxlen| mul.len().checked_sub(maxlen))
.unwrap_or(0);
- let mut new_deque: VecDeque<PyObjectRef> = mul.skip(skipped).cloned().collect();
+ mul.skip(skipped).cloned().collect()
+ };
+ let mut deque = zelf.borrow_deque_mut();
std::mem::swap(&mut *deque, &mut new_deque);
drop(deque);
Ok(zelf)
