Speed up loading by lazy adapters

This commit is contained in:
DBotThePony 2023-12-01 20:23:16 +07:00
parent efadaeb28c
commit f4cb791125
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -101,8 +101,8 @@ object Registries {
files: List<IStarboundFile>,
noinline keyProvider: (T) -> Pair<String, Int?>
): List<ForkJoinTask<*>> {
val adapter = Starbound.gson.getAdapter(T::class.java)
val elementAdapter = Starbound.gson.getAdapter(JsonElement::class.java)
val adapter by lazy { Starbound.gson.getAdapter(T::class.java) }
val elementAdapter by lazy { Starbound.gson.getAdapter(JsonElement::class.java) }
return files.map { listedFile ->
executor.submit {
@ -174,7 +174,7 @@ object Registries {
for ((ext, clazz) in fileMap) {
val fileList = files[ext] ?: continue
val adapter = Starbound.gson.getAdapter(clazz)
val adapter by lazy { Starbound.gson.getAdapter(clazz) }
for (listedFile in fileList) {
tasks.add(executor.submit {