DataFixerUpper icon indicating copy to clipboard operation
DataFixerUpper copied to clipboard

micro optimization

Open sunmisc opened this issue 2 years ago • 2 comments

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

sunmisc avatar Apr 12 '23 16:04 sunmisc

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

wolfieboy09 avatar Mar 28 '25 23:03 wolfieboy09

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

Yeah, thanks, that's better.

sunmisc avatar Mar 29 '25 22:03 sunmisc