Skip to content

Commit f309e2f

Browse files
committed
Restore the performance of checking for ThreadContextElement
1 parent dbb6169 commit f309e2f

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

Diff for: kotlinx-coroutines-core/common/src/internal/ThreadContext.common.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private val updateState =
5353
return state
5454
}
5555

56-
internal expect fun isZeroCount(countOrElement: Any?): Boolean
56+
internal expect inline fun isZeroCount(countOrElement: Any?): Boolean
5757

5858
// countOrElement is pre-cached in dispatched continuation
5959
// returns NO_THREAD_ELEMENTS if the contest does not have any ThreadContextElements
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
package kotlinx.coroutines.internal
22

3-
internal actual fun isZeroCount(countOrElement: Any?): Boolean = countOrElement is Int && countOrElement == 0
3+
@Suppress("NOTHING_TO_INLINE")
4+
internal actual inline fun isZeroCount(countOrElement: Any?): Boolean = countOrElement is Int && countOrElement == 0

Diff for: kotlinx-coroutines-core/jvm/src/internal/ThreadContext.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import kotlinx.coroutines.*
44
import kotlin.coroutines.*
55

66
// 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+
@Suppress("IMPLICIT_BOXING_IN_IDENTITY_EQUALS", "KotlinConstantConditions", "NOTHING_TO_INLINE")
8+
internal actual inline fun isZeroCount(countOrElement: Any?): Boolean = countOrElement === 0
99

1010
// top-level data class for a nicer out-of-the-box toString representation and class name
1111
@PublishedApi
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
package kotlinx.coroutines.internal
22

3-
internal actual fun isZeroCount(countOrElement: Any?): Boolean = countOrElement is Int && countOrElement == 0
3+
@Suppress("NOTHING_TO_INLINE")
4+
internal actual inline fun isZeroCount(countOrElement: Any?): Boolean = countOrElement is Int && countOrElement == 0

0 commit comments

Comments
 (0)