USE_CAFFEINE_INTERNER compilation flag

This commit is contained in:
DBotThePony 2024-02-02 18:18:41 +07:00
parent 278f66d892
commit 8c731366af
Signed by: DBot
GPG Key ID: DCC23B5715498507
5 changed files with 16 additions and 5 deletions

View File

@ -64,7 +64,18 @@ object Starbound : ISBFileLocator {
const val PROTOCOL_VERSION = 1
const val TICK_TIME_ADVANCE = 1.0 / 60.0
const val TICK_TIME_ADVANCE_NANOS = 16_666_666L
// compile flags. uuuugh
const val DEDUP_CELL_STATES = true
const val USE_CAFFEINE_INTERNER = false
fun <E : Any> interner(): Interner<E> {
return if (USE_CAFFEINE_INTERNER) Interner.newWeakInterner() else HashTableInterner()
}
fun <E : Any> interner(bits: Int): Interner<E> {
return if (USE_CAFFEINE_INTERNER) Interner.newWeakInterner() else HashTableInterner(bits)
}
val thread = Thread(::universeThread, "Starbound Universe")
val mailbox = MailboxExecutorService(thread)
@ -87,7 +98,7 @@ object Starbound : ISBFileLocator {
// Hrm.
// val strings: Interner<String> = Interner.newWeakInterner()
// val strings: Interner<String> = Interner { it }
val STRINGS: Interner<String> = HashTableInterner(5)
val STRINGS: Interner<String> = interner(5)
private val LOGGER = LogManager.getLogger()

View File

@ -152,7 +152,7 @@ class SBPattern private constructor(
}
companion object : TypeAdapterFactory {
private val interner: Interner<SBPattern> = HashTableInterner(5)
private val interner: Interner<SBPattern> = Starbound.interner(5)
@JvmField
val EMPTY = raw("")

View File

@ -43,7 +43,7 @@ sealed class AbstractCell {
}
@JvmStatic
protected val POOL: Interner<ImmutableCell> = if (Starbound.DEDUP_CELL_STATES) HashTableInterner() else Interner { it }
protected val POOL: Interner<ImmutableCell> = if (Starbound.DEDUP_CELL_STATES) Starbound.interner() else Interner { it }
val EMPTY: ImmutableCell = POOL.intern(ImmutableCell(AbstractTileState.EMPTY, AbstractTileState.EMPTY, AbstractLiquidState.EMPTY, 0, 0, 0, false))
val NULL: ImmutableCell = POOL.intern(ImmutableCell(AbstractTileState.NULL, AbstractTileState.NULL, AbstractLiquidState.EMPTY, 0, 0, 0, false))

View File

@ -30,7 +30,7 @@ sealed class AbstractLiquidState {
}
@JvmStatic
protected val POOL: Interner<ImmutableLiquidState> = if (Starbound.DEDUP_CELL_STATES) HashTableInterner() else Interner { it }
protected val POOL: Interner<ImmutableLiquidState> = if (Starbound.DEDUP_CELL_STATES) Starbound.interner() else Interner { it }
val EMPTY: ImmutableLiquidState = POOL.intern(ImmutableLiquidState())
}

View File

@ -35,7 +35,7 @@ sealed class AbstractTileState {
}
@JvmStatic
protected val POOL: Interner<ImmutableTileState> = if (Starbound.DEDUP_CELL_STATES) HashTableInterner() else Interner { it }
protected val POOL: Interner<ImmutableTileState> = if (Starbound.DEDUP_CELL_STATES) Starbound.interner() else Interner { it }
val EMPTY: ImmutableTileState = POOL.intern(ImmutableTileState(BuiltinMetaMaterials.EMPTY))
val NULL: ImmutableTileState = POOL.intern(ImmutableTileState(BuiltinMetaMaterials.NULL))