8189230: JDK method:java.lang.Integer.numberOfLeadingZeros(int) can be optimized

Directly return zero for a negative parameter instead of calculating

Reviewed-by: psandoz
This commit is contained in:
Brian Burkhalter 2018-03-15 08:11:01 -07:00
parent acb3103b8f
commit f5578ab220
2 changed files with 6 additions and 6 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -1771,8 +1771,8 @@ public final class Long extends Number implements Comparable<Long> {
@HotSpotIntrinsicCandidate
public static int numberOfLeadingZeros(long i) {
// HD, Figure 5-6
if (i == 0)
return 64;
if (i <= 0)
return i == 0 ? 64 : 0;
int n = 1;
int x = (int)(i >>> 32);
if (x == 0) { n += 32; x = (int)i; }