Skip to content

Commit 9ff3052

Browse files
committed
Improve precondition checks
1 parent 0ed0fd4 commit 9ff3052

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

kotlinx-coroutines-core/common/src/internal/RingBuffer.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal class RingBuffer<T>(val capacity: Int) : AbstractList<T>(), RandomAcces
1212
private set
1313

1414
override fun get(index: Int): T {
15-
require(index in 0 until size)
15+
require(index in 0 until size) { "Index out of bounds: $index" }
1616
@Suppress("UNCHECKED_CAST")
1717
return buffer[startIndex.forward(index)] as T
1818
}
@@ -70,9 +70,7 @@ internal class RingBuffer<T>(val capacity: Int) : AbstractList<T>(), RandomAcces
7070
* Add [element] to the buffer or fail with [IllegalStateException] if no free space available in the buffer
7171
*/
7272
fun add(element: T) {
73-
if (isFull()) {
74-
throw IllegalStateException("ring buffer is full")
75-
}
73+
check(!isFull()) { "Ring buffer is full" }
7674

7775
buffer[startIndex.forward(size)] = element
7876
size++

0 commit comments

Comments
 (0)