Skip to content

Commit fd49af5

Browse files
committed
Improve API
1 parent 28f8586 commit fd49af5

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

core/api/kotlinx-io-core.api

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public final class kotlinx/io/files/PathsKt {
284284

285285
public final class kotlinx/io/unsafe/UnsafeBufferOperations {
286286
public static final field INSTANCE Lkotlinx/io/unsafe/UnsafeBufferOperations;
287-
public static final field maxSafeWriteCapacity I
287+
public final fun getMaxSafeWriteCapacity ()I
288288
public final fun moveToTail (Lkotlinx/io/Buffer;[BII)V
289289
public static synthetic fun moveToTail$default (Lkotlinx/io/unsafe/UnsafeBufferOperations;Lkotlinx/io/Buffer;[BIIILjava/lang/Object;)V
290290
public final fun readFromHead (Lkotlinx/io/Buffer;Lkotlin/jvm/functions/Function3;)V

core/api/kotlinx-io-core.klib.api

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ final fun kotlinx.io.files/Path(kotlinx.io.files/Path, kotlin/Array<out kotlin/S
165165
final fun kotlinx.io/discardingSink(): kotlinx.io/RawSink // kotlinx.io/discardingSink|discardingSink(){}[0]
166166
final inline fun (kotlinx.io/Sink).kotlinx.io/writeToInternalBuffer(kotlin/Function1<kotlinx.io/Buffer, kotlin/Unit>) // kotlinx.io/writeToInternalBuffer|writeToInternalBuffer@kotlinx.io.Sink(kotlin.Function1<kotlinx.io.Buffer,kotlin.Unit>){}[0]
167167
final object kotlinx.io.unsafe/UnsafeBufferOperations { // kotlinx.io.unsafe/UnsafeBufferOperations|null[0]
168-
final const val maxSafeWriteCapacity // kotlinx.io.unsafe/UnsafeBufferOperations.maxSafeWriteCapacity|{}maxSafeWriteCapacity[0]
169-
final fun <get-maxSafeWriteCapacity>(): kotlin/Int // kotlinx.io.unsafe/UnsafeBufferOperations.maxSafeWriteCapacity.<get-maxSafeWriteCapacity>|<get-maxSafeWriteCapacity>(){}[0]
170168
final fun moveToTail(kotlinx.io/Buffer, kotlin/ByteArray, kotlin/Int = ..., kotlin/Int = ...) // kotlinx.io.unsafe/UnsafeBufferOperations.moveToTail|moveToTail(kotlinx.io.Buffer;kotlin.ByteArray;kotlin.Int;kotlin.Int){}[0]
171169
final inline fun readFromHead(kotlinx.io/Buffer, kotlin/Function3<kotlin/ByteArray, kotlin/Int, kotlin/Int, kotlin/Int>) // kotlinx.io.unsafe/UnsafeBufferOperations.readFromHead|readFromHead(kotlinx.io.Buffer;kotlin.Function3<kotlin.ByteArray,kotlin.Int,kotlin.Int,kotlin.Int>){}[0]
172170
final inline fun writeToTail(kotlinx.io/Buffer, kotlin/Int, kotlin/Function3<kotlin/ByteArray, kotlin/Int, kotlin/Int, kotlin/Int>) // kotlinx.io.unsafe/UnsafeBufferOperations.writeToTail|writeToTail(kotlinx.io.Buffer;kotlin.Int;kotlin.Function3<kotlin.ByteArray,kotlin.Int,kotlin.Int,kotlin.Int>){}[0]
171+
final val maxSafeWriteCapacity // kotlinx.io.unsafe/UnsafeBufferOperations.maxSafeWriteCapacity|{}maxSafeWriteCapacity[0]
172+
final fun <get-maxSafeWriteCapacity>(): kotlin/Int // kotlinx.io.unsafe/UnsafeBufferOperations.maxSafeWriteCapacity.<get-maxSafeWriteCapacity>|<get-maxSafeWriteCapacity>(){}[0]
173173
}
174174
final val kotlinx.io.files/SystemFileSystem // kotlinx.io.files/SystemFileSystem|{}SystemFileSystem[0]
175175
final fun <get-SystemFileSystem>(): kotlinx.io.files/FileSystem // kotlinx.io.files/SystemFileSystem.<get-SystemFileSystem>|<get-SystemFileSystem>(){}[0]

core/common/src/unsafe/UnsafeBufferOperations.kt

+11-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public object UnsafeBufferOperations {
1212
/**
1313
* Maximum value that is safe to pass to [writeToTail].
1414
*/
15-
public const val maxSafeWriteCapacity: Int = Segment.SIZE
15+
public val maxSafeWriteCapacity: Int = Segment.SIZE
1616

1717
/**
1818
* Moves [bytes] to the end of the [buffer].
@@ -74,12 +74,15 @@ public object UnsafeBufferOperations {
7474
* and the copy will be created if it could not be omitted.
7575
*
7676
* @throws IllegalStateException when [readAction] returns negative value or a values exceeding
77-
* the `endIndex - startIndex` value.
77+
* the `endIndexExclusive - startIndexInclusive` value.
7878
* @throws IllegalArgumentException when the [buffer] is empty.
7979
*
8080
* @sample kotlinx.io.samples.unsafe.UnsafeBufferOperationsSamples.readByteArrayFromHead
8181
*/
82-
public inline fun readFromHead(buffer: Buffer, readAction: (ByteArray, Int, Int) -> Int) {
82+
public inline fun readFromHead(
83+
buffer: Buffer,
84+
readAction: (bytes: ByteArray, startIndexInclusive: Int, endIndexExclusive: Int) -> Int
85+
) {
8386
require(!buffer.exhausted()) { "Buffer is empty" }
8487
val head = buffer.head!!
8588
val bytesRead = readAction(head.dataAsByteArray(true), head.pos, head.limit)
@@ -115,11 +118,14 @@ public object UnsafeBufferOperations {
115118
*
116119
* @throws IllegalStateException when [minimumCapacity] is too large and could not be fulfilled.
117120
* @throws IllegalStateException when [writeAction] returns a negative value or a value exceeding
118-
* the `endIndex - startIndex` value.
121+
* the `endIndexExclusive - startIndexInclusive` value.
119122
*
120123
* @sample kotlinx.io.samples.unsafe.UnsafeBufferOperationsSamples.writeByteArrayToTail
121124
*/
122-
public inline fun writeToTail(buffer: Buffer, minimumCapacity: Int, writeAction: (ByteArray, Int, Int) -> Int) {
125+
public inline fun writeToTail(
126+
buffer: Buffer, minimumCapacity: Int,
127+
writeAction: (bytes: ByteArray, startIndexInclusive: Int, endIndexExclusive: Int) -> Int
128+
) {
123129
val tail = buffer.writableSegment(minimumCapacity)
124130

125131
val data = tail.dataAsByteArray(false)

core/jvm/src/unsafe/UnsafeBufferOperationsJvm.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public inline fun UnsafeBufferOperations.writeToTail(
128128
public inline fun UnsafeBufferOperations.readBulk(
129129
buffer: Buffer,
130130
iovec: Array<ByteBuffer?>,
131-
readAction: (Array<ByteBuffer?>, Int) -> Long
131+
readAction: (iovec: Array<ByteBuffer?>, iovecSize: Int) -> Long
132132
) {
133133
val head = buffer.head ?: throw IllegalArgumentException("buffer is empty.")
134134
if (iovec.isEmpty()) throw IllegalArgumentException("iovec is empty.")

0 commit comments

Comments
 (0)