File tree 4 files changed +12
-4
lines changed
jsAndWasmShared/src/internal
4 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -53,15 +53,15 @@ private val updateState =
53
53
return state
54
54
}
55
55
56
+ internal expect fun isZeroCount (countOrElement : Any? ): Boolean
57
+
56
58
// countOrElement is pre-cached in dispatched continuation
57
59
// returns NO_THREAD_ELEMENTS if the contest does not have any ThreadContextElements
58
60
internal fun updateThreadContext (context : CoroutineContext , countOrElement : Any? ): Any? {
59
61
@Suppress(" NAME_SHADOWING" )
60
62
val countOrElement = countOrElement ? : threadContextElements(context)
61
- @Suppress(" IMPLICIT_BOXING_IN_IDENTITY_EQUALS" )
62
63
return when {
63
- countOrElement == = 0 -> NO_THREAD_ELEMENTS // very fast path when there are no active ThreadContextElements
64
- // ^^^ identity comparison for speed, we know zero always has the same identity
64
+ isZeroCount(countOrElement) -> NO_THREAD_ELEMENTS // very fast path when there are no active ThreadContextElements
65
65
countOrElement is Int -> {
66
66
// slow path for multiple active ThreadContextElements, allocates ThreadState for multiple old values
67
67
context.fold(ThreadState (context, countOrElement), updateState)
Original file line number Diff line number Diff line change
1
+ package kotlinx.coroutines.internal
2
+
3
+ internal actual fun isZeroCount (countOrElement : Any? ): Boolean = countOrElement is Int && countOrElement == 0
Original file line number Diff line number Diff line change @@ -3,7 +3,9 @@ package kotlinx.coroutines.internal
3
3
import kotlinx.coroutines.*
4
4
import kotlin.coroutines.*
5
5
6
-
6
+ // identity comparison for speed, we know zero always has the same identity
7
+ @Suppress(" IMPLICIT_BOXING_IN_IDENTITY_EQUALS" , " KotlinConstantConditions" )
8
+ internal actual fun isZeroCount (countOrElement : Any? ): Boolean = countOrElement == = 0
7
9
8
10
// top-level data class for a nicer out-of-the-box toString representation and class name
9
11
@PublishedApi
Original file line number Diff line number Diff line change
1
+ package kotlinx.coroutines.internal
2
+
3
+ internal actual fun isZeroCount (countOrElement : Any? ): Boolean = countOrElement is Int && countOrElement == 0
You can’t perform that action at this time.
0 commit comments