Skip to content

Commit 80c55a0

Browse files
committed
~get rid of ArrayQueue
1 parent 1fd7da3 commit 80c55a0

File tree

4 files changed

+16
-69
lines changed

4 files changed

+16
-69
lines changed

kotlinx-coroutines-core/js/src/JSDispatcher.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private class WindowMessageQueue(private val window: Window) : MessageQueue() {
129129
*
130130
* Yet there could be a long tail of "slow" reschedules, but it should be amortized by the queue size.
131131
*/
132-
internal abstract class MessageQueue : ArrayQueue<Runnable>() {
132+
internal abstract class MessageQueue : MutableList<Runnable> by ArrayDeque() {
133133
val yieldEvery = 16 // yield to JS macrotask event loop after this many processed messages
134134
private var scheduled = false
135135

@@ -138,7 +138,7 @@ internal abstract class MessageQueue : ArrayQueue<Runnable>() {
138138
abstract fun reschedule()
139139

140140
fun enqueue(element: Runnable) {
141-
addLast(element)
141+
add(element)
142142
if (!scheduled) {
143143
scheduled = true
144144
schedule()
@@ -153,7 +153,7 @@ internal abstract class MessageQueue : ArrayQueue<Runnable>() {
153153
element.run()
154154
}
155155
} finally {
156-
if (isEmpty) {
156+
if (isEmpty()) {
157157
scheduled = false
158158
} else {
159159
reschedule()

kotlinx-coroutines-core/js/src/Window.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
package kotlinx.coroutines
66

7-
import kotlinx.coroutines.internal.*
87
import org.w3c.dom.Window
98

109
/**
@@ -35,8 +34,8 @@ private fun Window.asWindowAnimationQueue(): WindowAnimationQueue =
3534
private class WindowAnimationQueue(private val window: Window) {
3635
private val dispatcher = window.asCoroutineDispatcher()
3736
private var scheduled = false
38-
private var current = ArrayQueue<CancellableContinuation<Double>>()
39-
private var next = ArrayQueue<CancellableContinuation<Double>>()
37+
private var current = ArrayDeque<CancellableContinuation<Double>>()
38+
private var next = ArrayDeque<CancellableContinuation<Double>>()
4039
private var timestamp = 0.0
4140

4241
fun enqueue(cont: CancellableContinuation<Double>) {

kotlinx-coroutines-core/js/src/internal/ArrayQueue.kt

Lines changed: 0 additions & 52 deletions
This file was deleted.

kotlinx-coroutines-core/js/test/MessageQueueTest.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,41 +36,41 @@ class MessageQueueTest {
3636

3737
@Test
3838
fun testBasic() {
39-
assertTrue(queue.isEmpty)
39+
assertTrue(queue.isEmpty())
4040
queue.enqueue(Box(1))
41-
assertFalse(queue.isEmpty)
41+
assertFalse(queue.isEmpty())
4242
assertTrue(scheduled)
4343
queue.enqueue(Box(2))
44-
assertFalse(queue.isEmpty)
44+
assertFalse(queue.isEmpty())
4545
scheduled = false
4646
queue.process()
4747
assertEquals(listOf(1, 2), processed)
4848
assertFalse(scheduled)
49-
assertTrue(queue.isEmpty)
49+
assertTrue(queue.isEmpty())
5050
}
5151

5252
@Test fun testRescheduleFromProcess() {
53-
assertTrue(queue.isEmpty)
53+
assertTrue(queue.isEmpty())
5454
queue.enqueue(ReBox(1))
55-
assertFalse(queue.isEmpty)
55+
assertFalse(queue.isEmpty())
5656
assertTrue(scheduled)
5757
queue.enqueue(ReBox(2))
58-
assertFalse(queue.isEmpty)
58+
assertFalse(queue.isEmpty())
5959
scheduled = false
6060
queue.process()
6161
assertEquals(listOf(1, 2, 11, 12), processed)
6262
assertFalse(scheduled)
63-
assertTrue(queue.isEmpty)
63+
assertTrue(queue.isEmpty())
6464
}
6565

6666
@Test
6767
fun testResizeAndWrap() {
6868
repeat(10) { phase ->
6969
val n = 10 * (phase + 1)
70-
assertTrue(queue.isEmpty)
70+
assertTrue(queue.isEmpty())
7171
repeat(n) {
7272
queue.enqueue(Box(it))
73-
assertFalse(queue.isEmpty)
73+
assertFalse(queue.isEmpty())
7474
assertTrue(scheduled)
7575
}
7676
var countYields = 0
@@ -84,4 +84,4 @@ class MessageQueueTest {
8484
processed.clear()
8585
}
8686
}
87-
}
87+
}

0 commit comments

Comments
 (0)