-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add deque __imul__ method #3020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add deque __imul__ method #3020
Conversation
vm/src/stdlib/collections.rs
Outdated
@@ -59,9 +59,9 @@ mod _collections { | |||
} | |||
} | |||
|
|||
struct SimpleSeqDeque<'a>(PyRwLockReadGuard<'a, VecDeque<PyObjectRef>>); | |||
struct SimpleSeqDeque(VecDeque<PyObjectRef>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
vm/src/stdlib/collections.rs
Outdated
@@ -471,6 +471,23 @@ mod _collections { | |||
}) | |||
} | |||
|
|||
#[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! thanks!
Closes #2839
Add
deque.__imul__()
method