-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
dev: swap_remove #11405
dev: swap_remove #11405
Conversation
should we pin clippy for the bins to |
yep, done here #11401 |
@@ -106,7 +106,7 @@ where | |||
/// # Panics | |||
/// If the index is out of bounds. | |||
pub fn remove_peer(&mut self, index: usize) -> Peer<C, Pool> { | |||
self.peers.remove(index) | |||
self.peers.swap_remove(index) |
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 we can't do because this messes with the ordering
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.
oh ok, didn't know peers ordering was important, will revert
@@ -383,7 +383,7 @@ where | |||
.into()) | |||
} | |||
|
|||
let sealed_target = headers.remove(0).seal_slow(); | |||
let sealed_target = headers.swap_remove(0).seal_slow(); |
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 fine because we only need the first one and aren't using it anymore
@@ -303,7 +303,7 @@ where | |||
let (fut, keep_alive) = self.payload_jobs[job].0.resolve(); | |||
|
|||
if keep_alive == KeepPayloadJobAlive::No { | |||
let (_, id) = self.payload_jobs.remove(job); | |||
let (_, id) = self.payload_jobs.swap_remove(job); |
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 also fine because we always find the index first and the ordering doesn't matter
Replaces remove with swap_remove for optimized removal of items in a Vec where preservation of order of the items isn't needed.