Pre-allocate arrays in seperate function

This commit is contained in:
Stedoss 2025-02-23 21:54:50 +00:00
parent 3ea6c2e8e4
commit d0ef99728e

View File

@ -189,17 +189,20 @@ class WTC {
} }
private fun seperate(stream: String): FrameLists { private fun seperate(stream: String): FrameLists {
val wList = mutableListOf<Int>() val frames = stream.split(',')
val xList = mutableListOf<Short>() val frameCount = frames.size
val yList = mutableListOf<Short>()
val zList = mutableListOf<Byte>()
for (frame in stream.split(",")) { val ws = IntArray(frameCount)
val xs = ShortArray(frameCount)
val ys = ShortArray(frameCount)
val zs = ByteArray(frameCount)
for ((i, frame) in frames.withIndex()) {
if (frame.isEmpty()) { if (frame.isEmpty()) {
continue continue
} }
val splitFrame = frame.split("|") val splitFrame = frame.split('|')
val w = splitFrame[0].toInt() val w = splitFrame[0].toInt()
val x = splitFrame[1].toFloat() val x = splitFrame[1].toFloat()
val y = splitFrame[2].toFloat() val y = splitFrame[2].toFloat()
@ -216,17 +219,17 @@ class WTC {
if (yy <= -0x8000) yy = -0x8000 if (yy <= -0x8000) yy = -0x8000
else if (yy >= 0x7FFF) yy = 0x7FFF else if (yy >= 0x7FFF) yy = 0x7FFF
wList.add(w) ws[i] = w
xList.add(xx.toShort()) xs[i] = xx.toShort()
yList.add(yy.toShort()) ys[i] = yy.toShort()
zList.add(zz.toByte()) zs[i] = zz.toByte()
} }
return FrameLists( return FrameLists(
x = xList.toShortArray(), x = xs,
y = yList.toShortArray(), y = ys,
z = zList.toByteArray(), z = zs,
w = wList.toIntArray(), w = ws,
) )
} }