com.jtransc.gen.common.StringPool.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jtransc-core Show documentation
Show all versions of jtransc-core Show documentation
JVM AOT compiler currently generating JavaScript, C++, Haxe, with initial focus on Kotlin and games.
package com.jtransc.gen.common
class StringPool {
enum class Type { GLOBAL, PER_CLASS }
private var lastId = 0
private val stringIds = hashMapOf()
private var valid = false
private var cachedEntries = listOf()
fun alloc(str: String): Int {
return stringIds.getOrPut(str) {
valid = false
lastId++
}
}
fun getAllSorted(): List {
if (!valid) {
cachedEntries = stringIds.entries.map { CommonGenerator.StringInPool(it.value, it.key) }.sortedBy { it.id }.toList()
valid = true
}
return cachedEntries
}
}