Repository navigation
Add deque __imul__ method - #3020
Conversation
| } | ||
|
|
||
| struct SimpleSeqDeque<'a>(PyRwLockReadGuard<'a, VecDeque<PyObjectRef>>); | ||
| struct SimpleSeqDeque(VecDeque<PyObjectRef>); |
There was a problem hiding this comment.
This is designed to borrow VecDeque but after this change, it will be cloned to make this struct.
There was a problem hiding this comment.
I switched to clone because it seemed like the easiest way to implement for the write guard as well. If you want I can switch to struct SimpleSeqDeque<'a>(&'a VecDeque<PyObjectRef>); -- or do you know if there is a trait that PyRwLockReadGuard and PyRwLockWriteGuard implement which I can use?
|
|
||
| #[pymethod(magic)] | ||
| fn imul(zelf: PyRef<Self>, value: isize, vm: &VirtualMachine) -> PyResult<PyRef<Self>> { | ||
| let mut new_deque: VecDeque<PyObjectRef> = { |
There was a problem hiding this comment.
No reason to repeat ourselves here though, right? Either imul calls mul or mul calls imul, both can work. CPython has mul call into imul after doing a copy. For now, this can just call into mul and then swap the deques. We can time it at some later point to see if the opposite yields any better results (though I'm guessing the difference would be small to negligible).
Closes #2839
Add
deque.__imul__()method