Skip to content

Commit

Permalink
Use a "small vec" in Events
Browse files Browse the repository at this point in the history
Right now just specialize one element as that's the same size as a vector, but
we can consider adding more later.

Closes rust-lang#203
  • Loading branch information
alexcrichton committed Nov 5, 2016
1 parent e4ffc27 commit 5d92957
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/task_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,25 +208,37 @@ pub trait EventSet: Send + Sync + 'static {

// A collection of UnparkEvents to trigger on `unpark`
#[derive(Clone)]
struct Events {
set: Vec<UnparkEvent>, // TODO: change to some SmallVec
enum Events {
Zero,
One(UnparkEvent),
Lots(Vec<UnparkEvent>),
}

impl Events {
fn new() -> Events {
Events { set: Vec::new() }
Events::Zero
}

fn trigger(&self) {
for event in self.set.iter() {
event.set.insert(event.item)
match *self {
Events::Zero => {}
Events::One(ref event) => event.set.insert(event.item),
Events::Lots(ref list) => {
for event in list {
event.set.insert(event.item);
}
}
}
}

fn with_event(&self, event: UnparkEvent) -> Events {
let mut set = self.set.clone();
set.push(event);
Events { set: set }
let mut list = match *self {
Events::Zero => return Events::One(event),
Events::One(ref event) => vec![event.clone()],
Events::Lots(ref list) => list.clone(),
};
list.push(event);
Events::Lots(list)
}
}

Expand Down

0 comments on commit 5d92957

Please sign in to comment.