-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
None
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
In the current implementation, Long.toUnsignedLong(long, int) sometimes creates a BigInteger and calls its toString(int) method. However, we don't have to create the BigInteger. The string can be calculated by the following algorithm:
long leadingDigits = divideUnsigned(i, radix); // always positive
int lastDigit = (int)remainderUnsigned(i, radix);
yield toString(leadingDigits, radix) + Character.forDigit(lastDigit, radix);
This implementation prevents from creating an additional object and is typically faster than BigInteger.toString(int).
In the current implementation, Long.toUnsignedLong(long, int) sometimes creates a BigInteger and calls its toString(int) method. However, we don't have to create the BigInteger. The string can be calculated by the following algorithm:
long leadingDigits = divideUnsigned(i, radix); // always positive
int lastDigit = (int)remainderUnsigned(i, radix);
yield toString(leadingDigits, radix) + Character.forDigit(lastDigit, radix);
This implementation prevents from creating an additional object and is typically faster than BigInteger.toString(int).
- relates to
-
JDK-6322074 Converting integers to string as if unsigned
- Closed
- links to
-
Review openjdk/jdk/14654