Skip to content

micro optimization#78

Open
sunmisc wants to merge 3 commits into
Mojang:masterfrom
sunmisc:master
Open

micro optimization#78
sunmisc wants to merge 3 commits into
Mojang:masterfrom
sunmisc:master

Conversation

@sunmisc

@sunmisc sunmisc commented Apr 12, 2023

Copy link
Copy Markdown

use a faster calculation of the power of two closest to input - 1, which uses bitwise operations at the hardware level (Intrinsic)

@wolfieboy09

Copy link
Copy Markdown

What about return (-1 >>> Integer.numberOfLeadingZeros(input - 1)) + 1;? Makes the function into one line

@sunmisc

sunmisc commented Mar 29, 2025

Copy link
Copy Markdown
Author

What about return (-1 >>> Integer.numberOfLeadingZeros(input - 1)) + 1;? Makes the function into one line

Yeah, thanks, that's better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants