Skip to content

Commit 7039f43

Browse files
committed
chore: Replace generational-arena with slotmap
1 parent 171a73e commit 7039f43

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

Cargo.lock

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ log-panics = { version = "2.1.0", features = ["with-backtrace"]}
4646
tracing = {version = "0.1.40", features = ["log", "log-always"]}
4747

4848
url = "2.5.0"
49-
generational-arena = "0.2.9"
49+
slotmap = "1.0.7"
5050
async-channel = "2.2.0"
5151

5252
ureq = "2.9.6"

src/executor.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,34 @@ use crate::custom_event::RuffleEvent;
44
use crate::task::Task;
55
use crate::EventSender;
66
use async_channel::{unbounded, Receiver, Sender};
7-
use generational_arena::{Arena, Index};
87
use ruffle_core::backend::navigator::OwnedFuture;
98
use ruffle_core::loader::Error;
9+
use slotmap::{new_key_type, SlotMap};
1010
use std::sync::{Arc, Mutex, Weak};
1111
use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
1212

13+
new_key_type! {
14+
struct TaskKey;
15+
}
16+
1317
/// Exeuctor context passed to event sources.
1418
///
1519
/// All task handles are identical and interchangeable. Cloning a `TaskHandle`
1620
/// does not clone the underlying task.
1721
#[derive(Clone)]
1822
struct TaskHandle {
19-
/// The arena handle for a given task.
20-
handle: Index,
23+
/// The slotmap key for a given task.
24+
key: TaskKey,
2125

2226
/// The executor the task belongs to.
2327
executor: Arc<Mutex<NativeAsyncExecutor>>,
2428
}
2529

2630
impl TaskHandle {
2731
/// Construct a handle to a given task.
28-
fn for_task(task: Index, executor: Arc<Mutex<NativeAsyncExecutor>>) -> Self {
32+
fn for_task(task: TaskKey, executor: Arc<Mutex<NativeAsyncExecutor>>) -> Self {
2933
Self {
30-
handle: task,
34+
key: task,
3135
executor,
3236
}
3337
}
@@ -50,7 +54,7 @@ impl TaskHandle {
5054
self.executor
5155
.lock()
5256
.expect("able to lock executor")
53-
.wake(self.handle);
57+
.wake(self.key);
5458
}
5559

5660
/// Convert a voidptr into an `TaskHandle` reference, if non-null.
@@ -123,7 +127,7 @@ impl TaskHandle {
123127

124128
pub struct NativeAsyncExecutor {
125129
/// List of all spawned tasks.
126-
task_queue: Arena<Task>,
130+
task_queue: SlotMap<TaskKey, Task>,
127131

128132
/// Source of tasks sent to us by the `NavigatorBackend`.
129133
channel: Receiver<OwnedFuture<(), Error>>,
@@ -147,7 +151,7 @@ impl NativeAsyncExecutor {
147151
let (send, recv) = unbounded();
148152
let new_self = Arc::new_cyclic(|self_ref| {
149153
Mutex::new(Self {
150-
task_queue: Arena::new(),
154+
task_queue: SlotMap::with_key(),
151155
channel: recv,
152156
self_ref: self_ref.clone(),
153157
event_sender,
@@ -193,7 +197,7 @@ impl NativeAsyncExecutor {
193197
}
194198

195199
/// Mark a task as ready to proceed.
196-
fn wake(&mut self, task: Index) {
200+
fn wake(&mut self, task: TaskKey) {
197201
if let Some(task) = self.task_queue.get_mut(task) {
198202
if !task.is_completed() {
199203
task.set_ready();

0 commit comments

Comments
 (0)