void
void copied to clipboard
Add ByteArrayReader and Writer
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
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
}