void icon indicating copy to clipboard operation
void copied to clipboard

Add ByteArrayReader and Writer

Open GregHib opened this issue 1 year ago • 1 comments

java.nio.ByteBuffer does a lot of checks which adds up esp for map tile loading, might be worth having a byte array implementation for better performance

GregHib avatar Mar 10 '24 23:03 GregHib

Branchless readSmart(). Prob not worth using but I spent the time to make it so I've got to put it somewhere.

fun readSmart(): Int {
    val peek = buffer[position++].toInt() and 0xff
    val negative = peek - 127 // Check if < 127
    val signum = (negative shr 31) or (-negative ushr 31)
    val pos = signum and (signum shr 31).inv() // Convert to 0 if false or 1 if true
    val result = (peek shl (8 * pos) or (buffer[position].toInt() and 0xff) * pos) - (32768 * pos)
    position += 1 * pos
    return result
}

GregHib avatar Jan 31 '25 19:01 GregHib