Get rid of another map built in FastJarHandler

This commit is contained in:
Denis.Zharkov
2021-07-30 13:13:46 +03:00
committed by teamcityserver
parent 42b2605c2a
commit 2266a348c3
2 changed files with 14 additions and 13 deletions
@@ -31,7 +31,6 @@ class FastJarHandler(val fileSystem: FastJarFileSystem, path: String) {
} }
} }
val childrenMap = HashMap<FastJarVirtualFile, MutableList<VirtualFile>>(ourEntryMap.size)
myRoot = FastJarVirtualFile(this, "", -1, null) myRoot = FastJarVirtualFile(this, "", -1, null)
val filesByRelativePath = HashMap<String, FastJarVirtualFile>(ourEntryMap.size) val filesByRelativePath = HashMap<String, FastJarVirtualFile>(ourEntryMap.size)
@@ -41,13 +40,8 @@ class FastJarHandler(val fileSystem: FastJarFileSystem, path: String) {
getOrCreateFile(info, filesByRelativePath) getOrCreateFile(info, filesByRelativePath)
} }
for (child in filesByRelativePath.values) { for (node in filesByRelativePath.values) {
val parent = child.parent as? FastJarVirtualFile ?: continue node.initChildrenArrayFromList()
childrenMap.getOrPut(parent) { mutableListOf() }.add(child)
}
for ((key, childList) in childrenMap) {
key.children = childList.toTypedArray()
} }
} }
@@ -17,12 +17,19 @@ internal class FastJarVirtualFile(
private val myHandler: FastJarHandler, private val myHandler: FastJarHandler,
private val myName: CharSequence, private val myName: CharSequence,
private val myLength: Int, private val myLength: Int,
private val myParent: VirtualFile? private val myParent: FastJarVirtualFile?
) : VirtualFile() { ) : VirtualFile() {
private var myChildren = EMPTY_ARRAY private var myChildrenArray = EMPTY_ARRAY
fun setChildren(children: Array<VirtualFile>) { private val myChildrenList: MutableList<VirtualFile> = mutableListOf()
myChildren = children
init {
myParent?.myChildrenList?.add(this)
}
fun initChildrenArrayFromList() {
myChildrenArray = myChildrenList.toTypedArray()
myChildrenList.clear()
} }
override fun getName(): String { override fun getName(): String {
@@ -68,7 +75,7 @@ internal class FastJarVirtualFile(
} }
override fun getChildren(): Array<VirtualFile> { override fun getChildren(): Array<VirtualFile> {
return myChildren return myChildrenArray
} }
@Throws(IOException::class) @Throws(IOException::class)