Skip to content

Commit

Permalink
Remove MoveCharacters component cache
Browse files Browse the repository at this point in the history
Unnecessary and unsafe due to potential concurrent access
  • Loading branch information
NichtStudioCode committed Jun 6, 2024
1 parent bd31085 commit 4356f9c
Showing 1 changed file with 4 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package xyz.xenondevs.nova.ui.overlay.character

import it.unimi.dsi.fastutil.floats.Float2ObjectOpenHashMap
import net.kyori.adventure.text.Component
import xyz.xenondevs.nova.data.resources.builder.task.font.MoveCharactersContent
import xyz.xenondevs.nova.data.resources.lookup.ResourceLookups
Expand All @@ -9,8 +8,6 @@ import kotlin.math.roundToInt

object MoveCharacters {

private val componentCache = Float2ObjectOpenHashMap<Component>()

internal fun getMovingString(distance: Number): String =
getMovingString(distance.toFloat())

Expand All @@ -21,24 +18,15 @@ object MoveCharacters {

val num = abs((distance * MoveCharactersContent.PRECISION).roundToInt())
val buffer = StringBuffer()
for (bit in 0..<MoveCharactersContent.SIZE)
for (bit in 0..<MoveCharactersContent.SIZE) {
if (num and (1 shl bit) != 0)
buffer.appendCodePoint(start + bit)
}

return buffer.toString()
}

fun getMovingComponent(distance: Number): Component {
val distFloat = distance.toFloat()

var component = componentCache.get(distFloat)
if (component != null)
return component

component = Component.text(getMovingString(distFloat))
componentCache.put(distFloat, component)

return component
}
fun getMovingComponent(distance: Number): Component =
Component.text(getMovingString(distance.toFloat()))

}

0 comments on commit 4356f9c

Please sign in to comment.