@@ -26,12 +26,18 @@ public open class LinkedListNode : DisposableHandle {
26
26
public inline val prevNode get() = _prev
27
27
public inline val isRemoved get() = _removed
28
28
29
- public fun addLast (node : Node ) {
29
+ public fun addLast (node : Node ): Boolean {
30
30
val prev = this ._prev
31
+ if (prev is CLOSED ) return false
31
32
node._next = this
32
33
node._prev = prev
33
34
prev._next = node
34
35
this ._prev = node
36
+ return true
37
+ }
38
+
39
+ public fun close () {
40
+ addLast(CLOSED ())
35
41
}
36
42
37
43
/*
@@ -41,15 +47,6 @@ public open class LinkedListNode : DisposableHandle {
41
47
* invokes handler on remove
42
48
*/
43
49
public open fun remove (): Boolean {
44
- return removeImpl()
45
- }
46
-
47
- override fun dispose () {
48
- remove()
49
- }
50
-
51
- @PublishedApi
52
- internal fun removeImpl (): Boolean {
53
50
if (_removed ) return false
54
51
val prev = this ._prev
55
52
val next = this ._next
@@ -59,6 +56,10 @@ public open class LinkedListNode : DisposableHandle {
59
56
return true
60
57
}
61
58
59
+ override fun dispose () {
60
+ remove()
61
+ }
62
+
62
63
public fun addOneIfEmpty (node : Node ): Boolean {
63
64
if (_next != = this ) return false
64
65
addLast(node)
@@ -67,34 +68,7 @@ public open class LinkedListNode : DisposableHandle {
67
68
68
69
public inline fun addLastIf (node : Node , crossinline condition : () -> Boolean ): Boolean {
69
70
if (! condition()) return false
70
- addLast(node)
71
- return true
72
- }
73
-
74
- public inline fun addLastIfPrev (node : Node , predicate : (Node ) -> Boolean ): Boolean {
75
- if (! predicate(_prev )) return false
76
- addLast(node)
77
- return true
78
- }
79
-
80
- public inline fun addLastIfPrevAndIf (
81
- node : Node ,
82
- predicate : (Node ) -> Boolean , // prev node predicate
83
- crossinline condition : () -> Boolean // atomically checked condition
84
- ): Boolean {
85
- if (! predicate(_prev )) return false
86
- if (! condition()) return false
87
- addLast(node)
88
- return true
89
- }
90
-
91
- public fun helpRemove () {} // No concurrency on JS -> no removal
92
-
93
- public fun removeFirstOrNull (): Node ? {
94
- val next = _next
95
- if (next == = this ) return null
96
- check(next.removeImpl()) { " Should remove" }
97
- return next
71
+ return addLast(node)
98
72
}
99
73
}
100
74
@@ -116,3 +90,5 @@ public open class LinkedListHead : LinkedListNode() {
116
90
// just a defensive programming -- makes sure that list head sentinel is never removed
117
91
public final override fun remove (): Nothing = throw UnsupportedOperationException ()
118
92
}
93
+
94
+ private class CLOSED : LinkedListNode ()
0 commit comments