Skip to content

Commit 7c8e82a

Browse files
committed
Use j.u.HashMap instead of Scala Map
1 parent 632478a commit 7c8e82a

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

core/src/main/scala/org/scalajs/macrotaskexecutor/MacrotaskExecutor.scala

+11-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.scalajs.macrotaskexecutor
1818

19-
import scala.collection.mutable
19+
import java.util.HashMap
2020
import scala.concurrent.{ExecutionContext, ExecutionContextExecutor}
2121
import scala.scalajs.js
2222
import scala.util.Random
@@ -37,7 +37,7 @@ object MacrotaskExecutor extends ExecutionContextExecutor {
3737
private[this] val setImmediate: Runnable => Unit = {
3838
if (js.typeOf(js.Dynamic.global.setImmediate) == Undefined) {
3939
var nextHandle = 1
40-
val tasksByHandle = mutable.Map[Int, Runnable]()
40+
val tasksByHandle = new HashMap[Int, Runnable]
4141
var currentlyRunningATask = false
4242

4343
def canUsePostMessage(): Boolean = {
@@ -67,17 +67,15 @@ object MacrotaskExecutor extends ExecutionContextExecutor {
6767
if (currentlyRunningATask) {
6868
js.Dynamic.global.setTimeout(() => runIfPresent(handle), 0)
6969
} else {
70-
tasksByHandle.get(handle) match {
71-
case Some(task) =>
72-
currentlyRunningATask = true
73-
try {
74-
task.run()
75-
} finally {
76-
tasksByHandle -= handle
77-
currentlyRunningATask = false
78-
}
79-
80-
case None =>
70+
val task = tasksByHandle.get(handle)
71+
if (task ne null) {
72+
currentlyRunningATask = true
73+
try {
74+
task.run()
75+
} finally {
76+
tasksByHandle -= handle
77+
currentlyRunningATask = false
78+
}
8179
}
8280
}
8381

0 commit comments

Comments
 (0)