Use inlining for read/writeVar*
This commit is contained in:
parent
f64dcacd63
commit
a772a08a2f
@ -4,7 +4,7 @@ kotlin.code.style=official
|
||||
specifyKotlinAsDependency=false
|
||||
|
||||
projectGroup=ru.dbotthepony.kommons
|
||||
projectVersion=2.10.2
|
||||
projectVersion=2.10.3
|
||||
|
||||
guavaDepVersion=33.0.0
|
||||
gsonDepVersion=2.8.9
|
||||
|
@ -79,9 +79,9 @@ fun InputStream.readDouble() = Double.fromBits(readLong())
|
||||
data class VarIntReadResult(val value: Int, val cells: Int)
|
||||
data class VarLongReadResult(val value: Long, val cells: Int)
|
||||
|
||||
private fun readVarLongInfo(supplier: IntSupplier): VarLongReadResult {
|
||||
private inline fun readVarLongInfo(supplier: () -> Int): VarLongReadResult {
|
||||
var result = 0L
|
||||
var read = supplier.asInt
|
||||
var read = supplier()
|
||||
var i = 1
|
||||
|
||||
if (read == -1)
|
||||
@ -93,7 +93,7 @@ private fun readVarLongInfo(supplier: IntSupplier): VarLongReadResult {
|
||||
if (read and 0x80 == 0)
|
||||
break
|
||||
|
||||
read = supplier.asInt
|
||||
read = supplier()
|
||||
|
||||
if (read == -1)
|
||||
throw EOFException("Reached end of stream before finished reading variable length integer (read totally $i bytes)")
|
||||
@ -104,16 +104,16 @@ private fun readVarLongInfo(supplier: IntSupplier): VarLongReadResult {
|
||||
return VarLongReadResult(result, i)
|
||||
}
|
||||
|
||||
private fun readVarIntInfo(supplier: IntSupplier): VarIntReadResult {
|
||||
private inline fun readVarIntInfo(supplier: () -> Int): VarIntReadResult {
|
||||
val read = readVarLongInfo(supplier)
|
||||
return VarIntReadResult(read.value.toInt(), read.cells)
|
||||
}
|
||||
|
||||
private fun readVarInt(supplier: IntSupplier): Int {
|
||||
private inline fun readVarInt(supplier: () -> Int): Int {
|
||||
return readVarIntInfo(supplier).value
|
||||
}
|
||||
|
||||
private fun readVarLong(supplier: IntSupplier): Long {
|
||||
private inline fun readVarLong(supplier: () -> Int): Long {
|
||||
return readVarLongInfo(supplier).value
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ fun OutputStream.writeLong(value: Long) {
|
||||
fun OutputStream.writeFloat(value: Float) = writeInt(value.toBits())
|
||||
fun OutputStream.writeDouble(value: Double) = writeLong(value.toBits())
|
||||
|
||||
private fun writeVarLong(write: IntConsumer, value: Long): Int {
|
||||
private inline fun writeVarLong(write: (Int) -> Unit, value: Long): Int {
|
||||
var length = 9
|
||||
|
||||
while (length > 0) {
|
||||
@ -95,15 +95,15 @@ private fun writeVarLong(write: IntConsumer, value: Long): Int {
|
||||
}
|
||||
|
||||
for (octet in length downTo 1) {
|
||||
write.accept(((value ushr (octet * 7)) and 0x7FL).toInt() or 0x80)
|
||||
write(((value ushr (octet * 7)) and 0x7FL).toInt() or 0x80)
|
||||
}
|
||||
|
||||
write.accept((value and 0x7FL).toInt())
|
||||
write((value and 0x7FL).toInt())
|
||||
|
||||
return length + 1
|
||||
}
|
||||
|
||||
private fun writeVarInt(write: IntConsumer, value: Int): Int {
|
||||
private inline fun writeVarInt(write: (Int) -> Unit, value: Int): Int {
|
||||
return writeVarLong(write, value.toLong())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user