forked from TechEmpower/FrameworkBenchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Okio with kotlinx-io and remove unneeded code
The "JSON serialization" performance seems to be slightly less.
- Loading branch information
Showing
5 changed files
with
58 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
frameworks/Kotlin/vertx-web-kotlinx/src/main/kotlin/KotlinxIo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import io.vertx.core.streams.WriteStream | ||
import io.vertx.kotlin.coroutines.coAwait | ||
import kotlinx.coroutines.runBlocking | ||
import kotlinx.io.RawSink | ||
import kotlinx.io.readByteArray | ||
import io.vertx.core.buffer.Buffer as VertxBuffer | ||
import kotlinx.io.Buffer as KotlinxIoBuffer | ||
|
||
@Suppress("NOTHING_TO_INLINE") | ||
private inline fun Long.toIntOrThrow(): Int { | ||
require(this in Int.MIN_VALUE.toLong()..Int.MAX_VALUE.toLong()) | ||
return toInt() | ||
} | ||
|
||
@JvmInline | ||
value class VertxBufferWriteStreamSink(val writeStream: WriteStream<VertxBuffer>) : RawSink { | ||
override fun write(source: KotlinxIoBuffer, byteCount: Long) { | ||
runBlocking { | ||
// `source` is temporarily converted to a byte array because wrapping it as a Vert.x `Buffer` is too complicated to implement. | ||
writeStream.write(VertxBuffer.buffer(source.readByteArray(byteCount.toIntOrThrow()))).coAwait() | ||
} | ||
} | ||
|
||
override fun flush() {} | ||
|
||
override fun close() { | ||
writeStream.end() | ||
} | ||
} | ||
|
||
// not used currently | ||
fun WriteStream<VertxBuffer>.toRawSink(): RawSink = | ||
VertxBufferWriteStreamSink(this) | ||
|
||
|
||
@JvmInline | ||
value class VertxBufferSink(val vertxBuffer: VertxBuffer) : RawSink { | ||
override fun write(source: KotlinxIoBuffer, byteCount: Long) { | ||
// same problem as above | ||
vertxBuffer.appendBytes(source.readByteArray(byteCount.toIntOrThrow())) | ||
} | ||
|
||
override fun flush() {} | ||
|
||
override fun close() {} | ||
} | ||
|
||
fun VertxBuffer.toRawSink(): RawSink = | ||
VertxBufferSink(this) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
63
frameworks/Kotlin/vertx-web-kotlinx/src/main/kotlin/Okio.kt
This file was deleted.
Oops, something went wrong.