diff --git a/Cargo.toml b/Cargo.toml index 469ab1433..39cfe58d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ futures = { git = "https://github.com/alexcrichton/futures-rs" } log = "0.3" mio = { git = "https://github.com/carllerche/mio" } scoped-tls = "0.1.0" -slab = "0.2.0" +slab = { git = "https://github.com/carllerche/slab" } [dev-dependencies] env_logger = "0.3" diff --git a/src/event_loop/mod.rs b/src/event_loop/mod.rs index 9e339e26c..fe64a87b5 100644 --- a/src/event_loop/mod.rs +++ b/src/event_loop/mod.rs @@ -147,9 +147,9 @@ impl Loop { events: mio::Events::with_capacity(1024), tx: Arc::new(tx), rx: rx, - io_dispatch: RefCell::new(Slab::new_starting_at(0, SLAB_CAPACITY)), - task_dispatch: RefCell::new(Slab::new_starting_at(0, SLAB_CAPACITY)), - timeouts: RefCell::new(Slab::new_starting_at(0, SLAB_CAPACITY)), + io_dispatch: RefCell::new(Slab::with_capacity(SLAB_CAPACITY)), + task_dispatch: RefCell::new(Slab::with_capacity(SLAB_CAPACITY)), + timeouts: RefCell::new(Slab::with_capacity(SLAB_CAPACITY)), timer_wheel: RefCell::new(TimerWheel::new()), _future_registration: future_pair.0, future_readiness: Arc::new(MySetReadiness(future_pair.1)), @@ -388,8 +388,8 @@ impl Loop { }; let mut dispatch = self.io_dispatch.borrow_mut(); if dispatch.vacant_entry().is_none() { - let amt = dispatch.count(); - dispatch.grow(amt); + let amt = dispatch.len(); + dispatch.reserve_exact(amt); } let entry = dispatch.vacant_entry().unwrap(); try!(self.io.register(source, @@ -430,8 +430,8 @@ impl Loop { fn add_timeout(&self, at: Instant) -> io::Result<(usize, Instant)> { let mut timeouts = self.timeouts.borrow_mut(); if timeouts.vacant_entry().is_none() { - let len = timeouts.count(); - timeouts.grow(len); + let len = timeouts.len(); + timeouts.reserve_exact(len); } let entry = timeouts.vacant_entry().unwrap(); let timeout = self.timer_wheel.borrow_mut().insert(at, entry.index()); @@ -461,8 +461,8 @@ impl Loop { let unpark = { let mut dispatch = self.task_dispatch.borrow_mut(); if dispatch.vacant_entry().is_none() { - let len = dispatch.count(); - dispatch.grow(len); + let len = dispatch.len(); + dispatch.reserve_exact(len); } let entry = dispatch.vacant_entry().unwrap(); let token = TOKEN_START + 2 * entry.index() + 1; diff --git a/src/timer_wheel.rs b/src/timer_wheel.rs index 21250f334..4751b3144 100644 --- a/src/timer_wheel.rs +++ b/src/timer_wheel.rs @@ -1,6 +1,6 @@ //! A timer wheel implementation -use std::mem; +use std::{mem, usize}; use std::time::{Instant, Duration}; use slab::Slab; @@ -74,7 +74,7 @@ pub struct Timeout { slab_idx: usize, } -const EMPTY: usize = 0; +const EMPTY: usize = usize::MAX; const LEN: usize = 256; const MASK: usize = LEN - 1; const TICK_MS: u64 = 100; @@ -88,7 +88,7 @@ impl TimerWheel { pub fn new() -> TimerWheel { TimerWheel { wheel: vec![Slot { head: EMPTY, next_timeout: None }; LEN], - slab: Slab::new_starting_at(1, 256), + slab: Slab::with_capacity(256), start: Instant::now(), cur_wheel_tick: 0, cur_slab_idx: EMPTY, @@ -129,8 +129,8 @@ impl TimerWheel { // Next, make sure there's enough space in the slab for the timeout. if self.slab.vacant_entry().is_none() { - let amt = self.slab.count(); - self.slab.grow(amt); + let amt = self.slab.len(); + self.slab.reserve_exact(amt); } // Insert ourselves at the head of the linked list in the wheel.