Skip to content
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

Support multi completion events: v2 #130

Merged
merged 24 commits into from
Oct 27, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 56 additions & 5 deletions src/driver/op/slab_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
//! which holds the index of the first element of the list.
//! It also holds the index of the last element, to support
//! push operations without list traversal.
//!
//! SlabListIndices may be upgraded to a SlabList, by providing
//! a reference to the backing slab. This seperates the SlabListIndices
//! from the lifetime of the storage (at type level only).
use slab::Slab;
use std::ops::{Deref, DerefMut};

Expand Down Expand Up @@ -102,7 +98,12 @@ impl<'a, T> SlabList<'a, T> {
next: usize::MAX,
};
self.index.end = self.slab.insert(entry);
self.slab[prev].next = self.index.end;
if prev != usize::MAX {
self.slab[prev].next = self.index.end;
} else {
self.index.start = self.index.end;
}

}

/// Consume the list, without dropping entries, returning just the start and end indices
Expand All @@ -119,3 +120,53 @@ impl<'a, T> Drop for SlabList<'a, T> {
}
}
}



mod test {
use super::*;

#[test]
fn push_pop() {
let mut slab = Slab::with_capacity(8);
let mut list = SlabListIndices::new().into_list(&mut slab);
assert!(list.is_empty());
assert_eq!(list.pop(), None);
for i in 0..5 {
list.push(i);
assert_eq!(list.peek_end(), Some(&i));
assert!(!list.is_empty());
assert!(!list.slab.is_empty());
}
for i in 0..5 {
assert_eq!(list.pop(), Some(i))
}
assert!(list.is_empty());
assert!(list.slab.is_empty());
assert_eq!(list.pop(), None);
}

#[test]
fn entries_freed_on_drop() {
let mut slab = Slab::with_capacity(8);
{
let mut list = SlabListIndices::new().into_list(&mut slab);
list.push(42);
assert!(!list.is_empty());
}
assert!(slab.is_empty());
}

#[test]
fn entries_kept_on_converion_to_index() {
let mut slab = Slab::with_capacity(8);
{
let mut list = SlabListIndices::new().into_list(&mut slab);
list.push(42);
assert!(!list.is_empty());
// This forgets the entries
let _ = list.into_indices();
}
assert!(!slab.is_empty());
}
}
FrankReh marked this conversation as resolved.
Show resolved Hide resolved