From 920d57563bcc82aa1ee7693ae283e24261ecfcfe Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Fri, 30 Jul 2021 17:42:46 +0300 Subject: [PATCH] Add fast-path for filename String creation In most cases, it's encoded with ASCI --- .../kotlin/cli/jvm/compiler/jarfs/ZipImplementation.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/jarfs/ZipImplementation.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/jarfs/ZipImplementation.kt index 0976bf68c0f..8c91a8adc4d 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/jarfs/ZipImplementation.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/jarfs/ZipImplementation.kt @@ -97,7 +97,11 @@ fun MappedByteBuffer.parseCentralDirectory(): List { position(currentOffset + 46) get(bytesForName) - val name = String(bytesForName) + val name = + if (bytesForName.all { it >= 0 }) + String(bytesForName.asASCICharArray()) + else + String(bytesForName, Charsets.UTF_8) currentOffset += 46 + fileNameLength + extraLength + fileCommentLength @@ -120,4 +124,6 @@ fun MappedByteBuffer.parseCentralDirectory(): List { return result } +private fun ByteArray.asASCICharArray(): CharArray = CharArray(size) { this@asASCICharArray[it].toChar() } + private fun ByteBuffer.getUnsignedShort(offset: Int): Int = java.lang.Short.toUnsignedInt(getShort(offset))