src/share/classes/java/lang/Integer.java
Print this page
rev 6518 : 8007398: Peformance improvements to Integer and Long string formatting.
Contributed-by: Steven Schlansker <stevenschlansker@gmail.com>
*** 24,34 ****
*/
package java.lang;
import java.lang.annotation.Native;
- import java.util.Properties;
/**
* The {@code Integer} class wraps a value of the primitive type
* {@code int} in an object. An object of type {@code Integer}
* contains a single field whose type is {@code int}.
--- 24,33 ----
*** 183,193 ****
* @return an unsigned string representation of the argument in the specified radix.
* @see #toString(int, int)
* @since 1.8
*/
public static String toUnsignedString(int i, int radix) {
! return Long.toString(toUnsignedLong(i), radix);
}
/**
* Returns a string representation of the integer argument as an
* unsigned integer in base 16.
--- 182,192 ----
* @return an unsigned string representation of the argument in the specified radix.
* @see #toString(int, int)
* @since 1.8
*/
public static String toUnsignedString(int i, int radix) {
! return Long.toUnsignedString(toUnsignedLong(i), radix);
}
/**
* Returns a string representation of the integer argument as an
* unsigned integer in base 16.
*** 306,325 ****
/**
* Convert the integer to an unsigned number.
*/
private static String toUnsignedString0(int i, int shift) {
! char[] buf = new char[32];
! int charPos = 32;
int radix = 1 << shift;
int mask = radix - 1;
do {
buf[--charPos] = digits[i & mask];
i >>>= shift;
} while (i != 0);
! return new String(buf, charPos, (32 - charPos));
}
final static char [] DigitTens = {
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
--- 305,328 ----
/**
* Convert the integer to an unsigned number.
*/
private static String toUnsignedString0(int i, int shift) {
! // assert shift > 0 && shift <=5 : "Illegal shift value";
! int mag = Integer.SIZE - Integer.numberOfLeadingZeros(i);
! int chars = Math.max(((mag + (shift - 1)) / shift), 1);
! char[] buf = new char[chars];
! int charPos = chars;
int radix = 1 << shift;
int mask = radix - 1;
do {
buf[--charPos] = digits[i & mask];
i >>>= shift;
} while (i != 0);
! // Use special constructor which takes over "buf".
! return new String(buf, true);
}
final static char [] DigitTens = {
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
*** 873,882 ****
--- 876,886 ----
/**
* Returns the value of this {@code Integer} as a {@code long}
* after a widening primitive conversion.
* @jls 5.1.2 Widening Primitive Conversions
+ * @see Integer#toUnsignedLong(int)
*/
public long longValue() {
return (long)value;
}