Avoid redundant lookups in the active slab when spawning new tasks (#96)
This commit is contained in:
parent
7ffdf5ba92
commit
568a314ad9
10
src/lib.rs
10
src/lib.rs
|
@ -151,7 +151,8 @@ impl<'a> Executor<'a> {
|
||||||
let mut active = self.state().active.lock().unwrap();
|
let mut active = self.state().active.lock().unwrap();
|
||||||
|
|
||||||
// Remove the task from the set of active tasks when the future finishes.
|
// Remove the task from the set of active tasks when the future finishes.
|
||||||
let index = active.vacant_entry().key();
|
let entry = active.vacant_entry();
|
||||||
|
let index = entry.key();
|
||||||
let state = self.state().clone();
|
let state = self.state().clone();
|
||||||
let future = async move {
|
let future = async move {
|
||||||
let _guard = CallOnDrop(move || drop(state.active.lock().unwrap().try_remove(index)));
|
let _guard = CallOnDrop(move || drop(state.active.lock().unwrap().try_remove(index)));
|
||||||
|
@ -164,7 +165,7 @@ impl<'a> Executor<'a> {
|
||||||
.propagate_panic(true)
|
.propagate_panic(true)
|
||||||
.spawn_unchecked(|()| future, self.schedule())
|
.spawn_unchecked(|()| future, self.schedule())
|
||||||
};
|
};
|
||||||
active.insert(runnable.waker());
|
entry.insert(runnable.waker());
|
||||||
|
|
||||||
runnable.schedule();
|
runnable.schedule();
|
||||||
task
|
task
|
||||||
|
@ -398,7 +399,8 @@ impl<'a> LocalExecutor<'a> {
|
||||||
let mut active = self.inner().state().active.lock().unwrap();
|
let mut active = self.inner().state().active.lock().unwrap();
|
||||||
|
|
||||||
// Remove the task from the set of active tasks when the future finishes.
|
// Remove the task from the set of active tasks when the future finishes.
|
||||||
let index = active.vacant_entry().key();
|
let entry = active.vacant_entry();
|
||||||
|
let index = entry.key();
|
||||||
let state = self.inner().state().clone();
|
let state = self.inner().state().clone();
|
||||||
let future = async move {
|
let future = async move {
|
||||||
let _guard = CallOnDrop(move || drop(state.active.lock().unwrap().try_remove(index)));
|
let _guard = CallOnDrop(move || drop(state.active.lock().unwrap().try_remove(index)));
|
||||||
|
@ -411,7 +413,7 @@ impl<'a> LocalExecutor<'a> {
|
||||||
.propagate_panic(true)
|
.propagate_panic(true)
|
||||||
.spawn_unchecked(|()| future, self.schedule())
|
.spawn_unchecked(|()| future, self.schedule())
|
||||||
};
|
};
|
||||||
active.insert(runnable.waker());
|
entry.insert(runnable.waker());
|
||||||
|
|
||||||
runnable.schedule();
|
runnable.schedule();
|
||||||
task
|
task
|
||||||
|
|
Loading…
Reference in New Issue