RFR 8209171 : Simplify Java implementation of Integer/Long.numberOfTrailingZeros() (original) (raw)

Martin Buchholz martinrb at google.com
Mon Aug 13 17:58:01 UTC 2018


On Mon, Aug 13, 2018 at 10:10 AM, Ivan Gerasimov <ivan.gerasimov at oracle.com> wrote:

Hi Martin!

Good point about the command line flags, thanks! These variants are close to numberOfTrailingZeros07 that I've already tested, though you did better by saving one arithmetic operation at the return line! Right. At this point

    return n + i - (i >> 1);

i is either 1 or 3, and

i - (i >> 1)

is equivalent to

1 + (i >>> 1)

so just initialize n to 1 instead. Very much like Integer.numberOfLeadingZeros does.



More information about the core-libs-dev mailing list