Prefer pop_first if it is available (#3084)

This commit is contained in:
Kaede Hoshikawa 2023-01-08 23:09:49 +09:00 committed by GitHub
parent ec4eca4fcb
commit b55be12d3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,12 +46,20 @@ impl TopologicalQueue {
} }
/// Take a single entry, preferring parents over children /// Take a single entry, preferring parents over children
#[rustversion::before(1.66)]
fn pop_topmost(&mut self) -> Option<QueueEntry> { fn pop_topmost(&mut self) -> Option<QueueEntry> {
// To be replaced with BTreeMap::pop_first once it is stable. // BTreeMap::pop_first is available after 1.66.
let key = *self.inner.keys().next()?; let key = *self.inner.keys().next()?;
self.inner.remove(&key) self.inner.remove(&key)
} }
/// Take a single entry, preferring parents over children
#[rustversion::since(1.66)]
#[inline]
fn pop_topmost(&mut self) -> Option<QueueEntry> {
self.inner.pop_first().map(|(_, v)| v)
}
/// Drain all entries, such that children are queued before parents /// Drain all entries, such that children are queued before parents
fn drain_post_order_into(&mut self, queue: &mut Vec<QueueEntry>) { fn drain_post_order_into(&mut self, queue: &mut Vec<QueueEntry>) {
if self.inner.is_empty() { if self.inner.is_empty() {