From 08ee12bcc997cc36b500d49c8167a991902d580e Mon Sep 17 00:00:00 2001 From: godotg Date: Sat, 6 Jul 2024 16:38:51 +0800 Subject: [PATCH] perf[kotlin]: do not use java language in kotlin --- .../src/main/resources/kotlin/ByteBuffer.kt | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/protocol/src/main/resources/kotlin/ByteBuffer.kt b/protocol/src/main/resources/kotlin/ByteBuffer.kt index af592099..e79ebf94 100644 --- a/protocol/src/main/resources/kotlin/ByteBuffer.kt +++ b/protocol/src/main/resources/kotlin/ByteBuffer.kt @@ -1,7 +1,5 @@ ${protocol_root_path} -import java.nio.charset.Charset - class ByteBuffer { private var buffer = ByteArray(INIT_SIZE) private var writeOffset = 0 @@ -317,20 +315,20 @@ class ByteBuffer { // *******************************************float*************************************************** fun writeFloat(value: Float) { - writeRawInt(java.lang.Float.floatToRawIntBits(value)) + writeRawInt(value.toBits()) } fun readFloat(): Float { - return java.lang.Float.intBitsToFloat(readRawInt()) + return Float.fromBits(readRawInt()) } // *******************************************double*************************************************** fun writeDouble(value: Double) { - writeRawLong(java.lang.Double.doubleToRawLongBits(value)) + writeRawLong(value.toBits()) } fun readDouble(): Double { - return java.lang.Double.longBitsToDouble(readRawLong()) + return Double.fromBits(readRawLong()) } fun writeString(value: String?) { @@ -338,7 +336,7 @@ class ByteBuffer { writeInt(0) return } - val bytes = value.toByteArray(DEFAULT_CHARSET) + val bytes = value.toByteArray() writeInt(bytes.size) writeBytes(bytes) } @@ -349,7 +347,7 @@ class ByteBuffer { return "" } val bytes = readBytes(length) - return String(bytes, DEFAULT_CHARSET) + return String(bytes) } fun writeBooleanArray(array: Array) { @@ -1233,9 +1231,5 @@ class ByteBuffer { companion object { private const val INIT_SIZE = 128 private const val MAX_SIZE = 655537 - - // *******************************************String*************************************************** - const val DEFAULT_CHARSET_NAME = "UTF-8" - val DEFAULT_CHARSET = Charset.forName(DEFAULT_CHARSET_NAME) } } \ No newline at end of file