Skip to content

Commit 778b2ac

Browse files
committed
Update BufferedChannel.kt after migrating to Kotlin 1.7.20 and allWarningsAsErrors
1 parent 3165806 commit 778b2ac

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

Diff for: kotlinx-coroutines-core/common/src/channels/BufferedChannel.kt

+17-17
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ internal open class BufferedChannel<E>(
994994
if (bufferEndSegment.moveForward(ss)) {
995995
ss = findSegmentBufferOrLast(id, ss)
996996
if (ss.id != id) return
997-
val i = (b % SEGMENT_SIZE).toInt()
997+
// val i = (b % SEGMENT_SIZE).toInt()
998998
// if (ss.getState(i) === INTERRUPTED_RCV) ss.onSlotCleaned()
999999
return
10001000
}
@@ -1469,8 +1469,8 @@ internal open class BufferedChannel<E>(
14691469
final override fun cancel(cause: CancellationException?) { cancelImpl(cause) }
14701470

14711471
internal open fun cancelImpl(cause: Throwable?): Boolean {
1472-
val cause = cause ?: CancellationException("Channel was cancelled")
1473-
val wasClosed = closeImpl(cause, true)
1472+
val materializedCause = cause ?: CancellationException("Channel was cancelled")
1473+
val wasClosed = closeImpl(materializedCause, true)
14741474
removeRemainingBufferedElements()
14751475
onCancel(wasClosed)
14761476
return wasClosed
@@ -1726,6 +1726,7 @@ internal open class BufferedChannel<E>(
17261726
// #######################
17271727

17281728
private fun findSegmentSend(id: Long, start: ChannelSegment<E>) =
1729+
@Suppress("INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION")
17291730
sendSegment.findSegmentAndMoveForward(id, start, ::createSegment).let {
17301731
if (it.isClosed) {
17311732
completeCloseOrCancel()
@@ -1755,6 +1756,7 @@ internal open class BufferedChannel<E>(
17551756
}
17561757

17571758
private fun findSegmentReceive(id: Long, start: ChannelSegment<E>) =
1759+
@Suppress("INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION")
17581760
receiveSegment.findSegmentAndMoveForward(id, start, ::createSegment).let {
17591761
if (it.isClosed) {
17601762
completeCloseOrCancel()
@@ -1770,9 +1772,11 @@ internal open class BufferedChannel<E>(
17701772
}
17711773

17721774
private fun findSegmentHasElements(id: Long, start: ChannelSegment<E>) =
1775+
@Suppress("INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION")
17731776
receiveSegment.findSegmentAndMoveForward(id, start, ::createSegment)
17741777

17751778
private fun findSegmentBuffer(id: Long, start: ChannelSegment<E>) =
1779+
@Suppress("INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION")
17761780
bufferEndSegment.findSegmentAndMoveForward(id, start, ::createSegment)
17771781

17781782
// ##################
@@ -1885,38 +1889,34 @@ internal class ChannelSegment<E>(id: Long, prev: ChannelSegment<E>?, pointers: I
18851889
// # Manipulation with the Element Fields #
18861890
// ########################################
18871891

1888-
inline fun storeElement(index: Int, element: E) {
1892+
internal fun storeElement(index: Int, element: E) {
18891893
setElementLazy(index, element)
18901894
}
18911895

18921896
@Suppress("UNCHECKED_CAST")
1893-
inline fun getElement(index: Int) = data[index * 2].value as E
1897+
internal fun getElement(index: Int) = data[index * 2].value as E
18941898

1895-
inline fun retrieveElement(index: Int): E = getElement(index).also { cleanElement(index) }
1899+
internal fun retrieveElement(index: Int): E = getElement(index).also { cleanElement(index) }
18961900

1897-
inline fun cleanElement(index: Int) {
1901+
internal fun cleanElement(index: Int) {
18981902
setElementLazy(index, null)
18991903
}
19001904

1901-
private inline fun setElementLazy(index: Int, value: Any?) {
1905+
private fun setElementLazy(index: Int, value: Any?) {
19021906
data[index * 2].lazySet(value)
19031907
}
19041908

19051909
// ######################################
19061910
// # Manipulation with the State Fields #
19071911
// ######################################
19081912

1909-
inline fun getState(index: Int): Any? = data[index * 2 + 1].value
1913+
internal fun getState(index: Int): Any? = data[index * 2 + 1].value
19101914

1911-
inline fun setState(index: Int, value: Any?) {
1915+
internal fun setState(index: Int, value: Any?) {
19121916
data[index * 2 + 1].value = value
19131917
}
19141918

1915-
inline fun setStateLazy(index: Int, value: Any?) {
1916-
data[index * 2 + 1].lazySet(value)
1917-
}
1918-
1919-
inline fun casState(index: Int, from: Any?, to: Any?) = data[index * 2 + 1].compareAndSet(from, to)
1919+
internal fun casState(index: Int, from: Any?, to: Any?) = data[index * 2 + 1].compareAndSet(from, to)
19201920

19211921
// ########################
19221922
// # Cancellation Support #
@@ -2119,7 +2119,7 @@ private const val CLOSE_STATUS_SHIFT = 60
21192119
private const val COUNTER_MASK = (1L shl CLOSE_STATUS_SHIFT) - 1
21202120
private inline val Long.counter get() = this and COUNTER_MASK
21212121
private inline val Long.closeStatus: Int get() = (this shr CLOSE_STATUS_SHIFT).toInt()
2122-
private inline fun constructSendersAndCloseStatus(counter: Long, closeStatus: Int): Long =
2122+
private fun constructSendersAndCloseStatus(counter: Long, closeStatus: Int): Long =
21232123
(closeStatus.toLong() shl CLOSE_STATUS_SHIFT) + counter
21242124

21252125
/*
@@ -2150,4 +2150,4 @@ private val NO_CLOSE_CAUSE = Symbol("NO_CLOSE_CAUSE")
21502150
* [BufferedChannel.BufferedChannelIterator], should be marked with this interface
21512151
* to make the code faster and easier to read.
21522152
*/
2153-
internal interface Waiter
2153+
internal interface Waiter

0 commit comments

Comments
 (0)