Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ByteArrayReader and Writer #473

Open
GregHib opened this issue Mar 10, 2024 · 1 comment
Open

Add ByteArrayReader and Writer #473

GregHib opened this issue Mar 10, 2024 · 1 comment
Labels

Comments

@GregHib
Copy link
Owner

GregHib commented Mar 10, 2024

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 GregHib added enhancement New feature or request idea performance labels Mar 10, 2024
@GregHib
Copy link
Owner Author

GregHib commented Jan 31, 2025

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant