All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jtransc.gen.common.StringPool.kt Maven / Gradle / Ivy

Go to download

JVM AOT compiler currently generating JavaScript, C++, Haxe, with initial focus on Kotlin and games.

There is a newer version: 0.6.8
Show newest version
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
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy