Optimize FastJarHandler
- Do not use normalization as it seems unnecessary
This commit is contained in:
committed by
teamcityserver
parent
2266a348c3
commit
fa9f0d588d
@@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.jetbrains.kotlin.cli.jvm.compiler.jarfs
|
package org.jetbrains.kotlin.cli.jvm.compiler.jarfs
|
||||||
|
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileNotFoundException
|
import java.io.FileNotFoundException
|
||||||
@@ -36,8 +35,12 @@ class FastJarHandler(val fileSystem: FastJarFileSystem, path: String) {
|
|||||||
val filesByRelativePath = HashMap<String, FastJarVirtualFile>(ourEntryMap.size)
|
val filesByRelativePath = HashMap<String, FastJarVirtualFile>(ourEntryMap.size)
|
||||||
filesByRelativePath[""] = myRoot
|
filesByRelativePath[""] = myRoot
|
||||||
|
|
||||||
for (info in ourEntryMap.values) {
|
for (entryDescription in ourEntryMap.values) {
|
||||||
getOrCreateFile(info, filesByRelativePath)
|
if (!entryDescription.isDirectory) {
|
||||||
|
createFile(entryDescription, filesByRelativePath)
|
||||||
|
} else {
|
||||||
|
getOrCreateDirectory(entryDescription.relativePath, filesByRelativePath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (node in filesByRelativePath.values) {
|
for (node in filesByRelativePath.values) {
|
||||||
@@ -45,50 +48,37 @@ class FastJarHandler(val fileSystem: FastJarFileSystem, path: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getOrCreateFile(entry: ZipEntryDescription, map: MutableMap<String, FastJarVirtualFile>): FastJarVirtualFile {
|
private fun createFile(entry: ZipEntryDescription, directories: MutableMap<String, FastJarVirtualFile>): FastJarVirtualFile {
|
||||||
val entryName = entry.relativePath.normalizePath()
|
val (parentName, shortName) = entry.relativePath.splitPath()
|
||||||
|
|
||||||
return map.getOrPut(entryName) {
|
val parentFile = getOrCreateDirectory(parentName, directories)
|
||||||
val (parentName, shortName) = entryName.splitPath()
|
if ("." == shortName) {
|
||||||
|
return parentFile
|
||||||
val parentFile = getOrCreateDirectory(parentName, map)
|
|
||||||
if ("." == shortName) {
|
|
||||||
return parentFile
|
|
||||||
}
|
|
||||||
|
|
||||||
FastJarVirtualFile(
|
|
||||||
this, shortName,
|
|
||||||
if (entry.isDirectory) -1 else entry.uncompressedSize,
|
|
||||||
parentFile
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return FastJarVirtualFile(
|
||||||
|
this, shortName,
|
||||||
|
if (entry.isDirectory) -1 else entry.uncompressedSize,
|
||||||
|
parentFile
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getOrCreateDirectory(entryName: String, map: MutableMap<String, FastJarVirtualFile>): FastJarVirtualFile {
|
private fun getOrCreateDirectory(entryName: String, directories: MutableMap<String, FastJarVirtualFile>): FastJarVirtualFile {
|
||||||
return map.getOrPut(entryName) {
|
return directories.getOrPut(entryName) {
|
||||||
val entry = ourEntryMap["$entryName/"]
|
|
||||||
if (entry != null) {
|
|
||||||
return getOrCreateFile(entry, map)
|
|
||||||
}
|
|
||||||
val (parentPath, shortName) = entryName.splitPath()
|
val (parentPath, shortName) = entryName.splitPath()
|
||||||
require(entryName != parentPath) {
|
val parentFile = getOrCreateDirectory(parentPath, directories)
|
||||||
"invalid entry name: '" + entryName + "' in " + this.file.absolutePath + "; after split: " + Pair(parentPath, shortName)
|
|
||||||
}
|
|
||||||
val parentFile = getOrCreateDirectory(parentPath, map)
|
|
||||||
|
|
||||||
FastJarVirtualFile(this, shortName, -1, parentFile)
|
FastJarVirtualFile(this, shortName, -1, parentFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun String.normalizePath(): String {
|
|
||||||
if (endsWith('/')) return substring(0, length - 1).normalizePath()
|
|
||||||
if (startsWith('/') || startsWith('\\')) return substring(1, length).normalizePath()
|
|
||||||
if (!contains('\\')) return this
|
|
||||||
return FileUtil.normalize(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun String.splitPath(): Pair<String, String> {
|
private fun String.splitPath(): Pair<String, String> {
|
||||||
val slashIndex = lastIndexOf('/')
|
var slashIndex = this.length - 1
|
||||||
|
|
||||||
|
while (slashIndex >= 0 && this[slashIndex] != '/') {
|
||||||
|
slashIndex--
|
||||||
|
}
|
||||||
|
|
||||||
if (slashIndex == -1) return Pair("", this)
|
if (slashIndex == -1) return Pair("", this)
|
||||||
return Pair(substring(0, slashIndex), substring(slashIndex + 1))
|
return Pair(substring(0, slashIndex), substring(slashIndex + 1))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user