From 5358b3e4d0aea900f2ee99db54c8371735574994 Mon Sep 17 00:00:00 2001 From: Him188 Date: Thu, 25 Aug 2022 13:12:19 +0800 Subject: [PATCH] [core] slightly improve performance of `toUHexString` --- mirai-core-utils/src/commonMain/kotlin/Bytes.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mirai-core-utils/src/commonMain/kotlin/Bytes.kt b/mirai-core-utils/src/commonMain/kotlin/Bytes.kt index b820377a7..7bdf7eec3 100644 --- a/mirai-core-utils/src/commonMain/kotlin/Bytes.kt +++ b/mirai-core-utils/src/commonMain/kotlin/Bytes.kt @@ -89,8 +89,8 @@ public fun ByteArray.toUHexString( return buildString(length * 2) { this@toUHexString.forEachIndexed { index, it -> if (index in offset until lastIndex) { - var ret = it.toUByte().toString(16).uppercase() - if (ret.length == 1) ret = "0$ret" + val ret = it.toUByte().toString(16).uppercase() + if (ret.length == 1) append('0') append(ret) if (index < lastIndex - 1) append(separator) } @@ -112,8 +112,8 @@ public fun UByteArray.toUHexString(separator: String = " ", offset: Int = 0, len return buildString(length * 2) { this@toUHexString.forEachIndexed { index, it -> if (index in offset until lastIndex) { - var ret = it.toByte().toUByte().toString(16).uppercase() - if (ret.length == 1) ret = "0$ret" + val ret = it.toByte().toUByte().toString(16).uppercase() + if (ret.length == 1) append('0') append(ret) if (index < lastIndex - 1) append(separator) }