--- old/src/java.base/share/classes/java/math/BigInteger.java 2019-08-22 10:35:32.000000000 -0700 +++ new/src/java.base/share/classes/java/math/BigInteger.java 2019-08-22 10:35:31.000000000 -0700 @@ -3960,6 +3960,19 @@ return sb.toString(); } + private static void padWithZeros(StringBuilder buf, int len, int digits) { + if (digits > 0 && len < digits) { + int m = digits - len; + while (m >= NUM_ZEROS) { + buf.append(ZEROS); + m -= NUM_ZEROS; + } + if (m > 0) { + buf.append(ZEROS, 0, m); + } + } + } + /** * This method is used to perform toString when arguments are small. * A negative sign will be prepended if and only if {@code this < 0}. @@ -3973,6 +3986,7 @@ private void smallToString(int radix, StringBuilder buf, int digits) { if (signum == 0) { buf.append('0'); + padWithZeros(buf, 1, digits); return; } @@ -4006,19 +4020,8 @@ String s = Long.toString(digitGroups[numGroups-1], radix); // Pad with internal zeros if necessary. - if (digits > 0) { - int len = s.length() + (numGroups - 1)*digitsPerLong[radix]; - if (len < digits) { - int m = digits - len; - while (m >= NUM_ZEROS) { - buf.append(zeros); - m -= NUM_ZEROS; - } - if (m > 0) { - buf.append(zeros, 0, m); - } - } - } + padWithZeros(buf, s.length() + (numGroups - 1)*digitsPerLong[radix], + digits); // Put first digit group into result buffer buf.append(s); @@ -4029,7 +4032,7 @@ s = Long.toString(digitGroups[i], radix); int numLeadingZeros = digitsPerLong[radix] - s.length(); if (numLeadingZeros != 0) { - buf.append(zeros, 0, numLeadingZeros); + buf.append(ZEROS, 0, numLeadingZeros); } buf.append(s); } @@ -4114,11 +4117,11 @@ return cacheLine[exponent]; } - /* Size of zeros string. */ + /* Size of ZEROS string. */ private static int NUM_ZEROS = 63; - /* zero is a string of NUM_ZEROS consecutive zeros. */ - private static final String zeros = "0".repeat(NUM_ZEROS); + /* ZEROS is a string of NUM_ZEROS consecutive zeros. */ + private static final String ZEROS = "0".repeat(NUM_ZEROS); /** * Returns the decimal String representation of this BigInteger.