< prev index next >
src/java.base/share/classes/java/math/BigInteger.java
Print this page
@@ -3999,13 +3999,13 @@
// Append remaining digit groups padded with leading zeros
for (int i=numGroups-2; i >= 0; i--) {
// Prepend (any) leading zeros for this digit group
s = Long.toString(digitGroups[i], radix);
- int numLeadingZeros = digitsPerLong[radix]-s.length();
+ int numLeadingZeros = digitsPerLong[radix] - s.length();
if (numLeadingZeros != 0) {
- buf.append(zeros[numLeadingZeros]);
+ buf.append(zeros, 0, numLeadingZeros);
count += numLeadingZeros;
}
buf.append(s);
count += s.length();
}
@@ -4043,18 +4043,17 @@
// Pad with internal zeros if necessary.
// Don't pad if we're at the beginning of the string.
if (!atBeginning && len < digits) {
int m = digits - len;
- int zl1 = zeros.length - 1;
- while (m >= zl1) {
- sb.insert(pos, zeros[zl1]);
- pos += zl1;
- m -= zl1;
+ while (m >= NUM_ZEROS) {
+ sb.insert(pos, zeros, 0, NUM_ZEROS);
+ pos += NUM_ZEROS;
+ m -= NUM_ZEROS;
}
if (m > 0) {
- sb.insert(pos, zeros[m]);
+ sb.insert(pos, zeros, 0, m);
}
}
return;
}
@@ -4103,18 +4102,15 @@
powerCache = pc; // volatile write, publish
}
return cacheLine[exponent];
}
- /* zero[i] is a string of i consecutive zeros. */
- private static String[] zeros = new String[64];
- static {
- zeros[63] =
- "000000000000000000000000000000000000000000000000000000000000000";
- for (int i=0; i < 63; i++)
- zeros[i] = zeros[63].substring(0, i);
- }
+ /* 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);
/**
* Returns the decimal String representation of this BigInteger.
* The digit-to-character mapping provided by
* {@code Character.forDigit} is used, and a minus sign is
< prev index next >