Slightly improve memory usage of starbound pak fs
This commit is contained in:
parent
8d8143c914
commit
79381845b0
@ -1,7 +1,10 @@
|
|||||||
package ru.dbotthepony.kstarbound.io
|
package ru.dbotthepony.kstarbound.io
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectFunction
|
import it.unimi.dsi.fastutil.objects.Object2ObjectFunction
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap
|
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectMap
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectMaps
|
||||||
import ru.dbotthepony.kommons.gson.get
|
import ru.dbotthepony.kommons.gson.get
|
||||||
import ru.dbotthepony.kommons.io.readBinaryString
|
import ru.dbotthepony.kommons.io.readBinaryString
|
||||||
import ru.dbotthepony.kommons.io.readVarInt
|
import ru.dbotthepony.kommons.io.readVarInt
|
||||||
@ -48,10 +51,16 @@ class StarboundPak(val path: File, callback: (finished: Boolean, status: String)
|
|||||||
get() = false
|
get() = false
|
||||||
|
|
||||||
private var frozen = false
|
private var frozen = false
|
||||||
private val innerChildren = Object2ObjectLinkedOpenHashMap<String, IStarboundFile>()
|
private var innerChildren: Object2ObjectMap<String, IStarboundFile> = Object2ObjectArrayMap(2)
|
||||||
|
|
||||||
fun put(value: IStarboundFile) {
|
fun put(value: IStarboundFile) {
|
||||||
check(!frozen) { "Can't put, already frozen!" }
|
check(!frozen) { "Can't put, already frozen!" }
|
||||||
|
|
||||||
|
if (innerChildren is Object2ObjectArrayMap && innerChildren.size >= 8) {
|
||||||
|
innerChildren = Object2ObjectLinkedOpenHashMap(innerChildren)
|
||||||
|
children = Object2ObjectMaps.unmodifiable(innerChildren)
|
||||||
|
}
|
||||||
|
|
||||||
innerChildren[value.name] = value
|
innerChildren[value.name] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +70,8 @@ class StarboundPak(val path: File, callback: (finished: Boolean, status: String)
|
|||||||
return innerChildren.computeIfAbsent(name, Object2ObjectFunction { SBDirectory(it as String, this) }) as? SBDirectory ?: throw IllegalStateException("$name already exists (in ${computeFullPath()})")
|
return innerChildren.computeIfAbsent(name, Object2ObjectFunction { SBDirectory(it as String, this) }) as? SBDirectory ?: throw IllegalStateException("$name already exists (in ${computeFullPath()})")
|
||||||
}
|
}
|
||||||
|
|
||||||
override val children: Map<String, IStarboundFile> = Collections.unmodifiableMap(innerChildren)
|
override var children: Map<String, IStarboundFile> = Object2ObjectMaps.unmodifiable(innerChildren)
|
||||||
|
private set
|
||||||
|
|
||||||
fun freeze() {
|
fun freeze() {
|
||||||
check(!frozen) { "Already frozen" }
|
check(!frozen) { "Already frozen" }
|
||||||
|
Loading…
Reference in New Issue
Block a user