Make ByteArray#asHexString less slow
the old code was creating formatters (running regex) for each byte...
This commit is contained in:
parent
47ec175e27
commit
87e8db20d0
1 changed files with 8 additions and 4 deletions
|
@ -311,12 +311,16 @@ fun InputStream.hash(algorithm: HashingAlgorithm, bufferSize: Int = 8192): ByteA
|
|||
return digest.digest()
|
||||
}
|
||||
|
||||
private val hexChars = "0123456789abcdef".toCharArray()
|
||||
|
||||
fun ByteArray.asHexString(): String {
|
||||
val sb: StringBuilder = StringBuilder(size * 2)
|
||||
for (aHash in this) {
|
||||
sb.append("%02x".format(aHash.toInt() and 0xFF))
|
||||
val chars = CharArray(2 * size)
|
||||
forEachIndexed { i, byte ->
|
||||
val unsigned = byte.toInt() and 0xFF
|
||||
chars[2 * i] = hexChars[unsigned / 16]
|
||||
chars[2 * i + 1] = hexChars[unsigned % 16]
|
||||
}
|
||||
return sb.toString()
|
||||
return String(chars)
|
||||
}
|
||||
|
||||
fun JavaToolchainService.defaultJavaLauncher(project: Project): Provider<JavaLauncher> {
|
||||
|
|
Loading…
Reference in a new issue