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 {
val wList = mutableListOf<Int>()
val xList = mutableListOf<Short>()
val yList = mutableListOf<Short>()
val zList = mutableListOf<Byte>()
val frames = stream.split(',')
val frameCount = frames.size
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()) {
continue
}
val splitFrame = frame.split("|")
val splitFrame = frame.split('|')
val w = splitFrame[0].toInt()
val x = splitFrame[1].toFloat()
val y = splitFrame[2].toFloat()
@ -216,17 +219,17 @@ class WTC {
if (yy <= -0x8000) yy = -0x8000
else if (yy >= 0x7FFF) yy = 0x7FFF
wList.add(w)
xList.add(xx.toShort())
yList.add(yy.toShort())
zList.add(zz.toByte())
ws[i] = w
xs[i] = xx.toShort()
ys[i] = yy.toShort()
zs[i] = zz.toByte()
}
return FrameLists(
x = xList.toShortArray(),
y = yList.toShortArray(),
z = zList.toByteArray(),
w = wList.toIntArray(),
x = xs,
y = ys,
z = zs,
w = ws,
)
}