-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implement remove for RingBuf #19871
Implement remove for RingBuf #19871
Conversation
ad3823f
to
4bb716b
Compare
@@ -822,7 +822,7 @@ impl<T> RingBuf<T> { | |||
let old_tail = self.tail; | |||
self.tail = self.tail - 1; |
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.
Should I refactor these parts of insert
in line with remove
? IMO it's more readable.
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'm not sure what exactly you're picturing. Feel free to do anything you believe improves code quality :)
Done review. Once my issues are addressed, I'd still appreciate a second pair of eyes as this is a bunch of unsafe code. Actually upon reflection I think |
6d5b6d0
to
947355d
Compare
Done update. Yes, it didn't make sense that a combination of unsafe fns |
@@ -756,9 +754,9 @@ impl<T> RingBuf<T> { | |||
self.tail = self.wrap_index(self.tail - 1); | |||
|
|||
self.copy(self.tail, old_tail, 1); | |||
self.copy(old_tail, old_tail + 1, i); | |||
self.copy(old_tail, old_tail + 1, i - 1); |
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.
Pretty sure this should be i
still?
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.
Can be either way
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.
Ohhh I see right because we already moved the tail! Can you toss in a comment to this effect?
Round two done. |
@@ -719,7 +717,7 @@ impl<T> RingBuf<T> { | |||
let contiguous = self.tail <= self.head; | |||
|
|||
match (contiguous, distance_to_tail <= distance_to_head, idx >= self.tail) { | |||
(true, true, _) if i == 0 => { | |||
(true, true, _) if i == 0 => unsafe { |
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.
Thanks for not increasing the indent level :)
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.
Also, I get an unnecessary unsafe block warning here.
It's weird that |
I just did a read through. Didn't find anything objectionable. I do think we should change it to 31 instead of 15 though. I know it doesn't catch any bugs at the moment, but this has me paranoid. |
@cgaebel those semantics are the ones agreed upon by reform v1, for what it's worth. Feel free to make a formal argument against them in v2! |
A situation where insertion happened closer to tail in the head section (discontiguous), and at a non-zero index, wasn't possible with 7. IMO >15 doesn't really matter. |
f9ba541
to
bdbdd59
Compare
bdbdd59
to
59d4153
Compare
Again, looks good to me. Just making sure those were on purpose and not overlooked. |
Includes a fix for a small mistake in `fn insert` which is caught by test_insert for len=15, but not len=7. Part of rust-lang#18424 r? @gankro @csherratt @huonw
Includes a fix for a small mistake in
fn insert
which is caught by test_insert for len=15, but not len=7.Part of #18424
r? @gankro @csherratt @huonw