mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8337167: StringSize deduplication
Reviewed-by: liach, rriggs
This commit is contained in:
parent
487450cb5e
commit
7f11935461
8 changed files with 40 additions and 95 deletions
|
@ -121,6 +121,8 @@ import java.util.concurrent.ConcurrentMap;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import jdk.internal.util.DecimalDigits;
|
||||
|
||||
import sun.text.spi.JavaTimeDateTimePatternProvider;
|
||||
import sun.util.locale.provider.CalendarDataUtility;
|
||||
import sun.util.locale.provider.LocaleProviderAdapter;
|
||||
|
@ -2908,24 +2910,6 @@ public final class DateTimeFormatterBuilder {
|
|||
return new NumberPrinterParser(field, minWidth, maxWidth, signStyle, this.subsequentWidth + subsequentWidth);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copied from Long.stringSize
|
||||
*/
|
||||
private static int stringSize(long x) {
|
||||
int d = 1;
|
||||
if (x >= 0) {
|
||||
d = 0;
|
||||
x = -x;
|
||||
}
|
||||
long p = -10;
|
||||
for (int i = 1; i < 19; i++) {
|
||||
if (x > p)
|
||||
return i + d;
|
||||
p = 10 * p;
|
||||
}
|
||||
return 19 + d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean format(DateTimePrintContext context, StringBuilder buf) {
|
||||
Long valueLong = context.getValue(field);
|
||||
|
@ -2934,7 +2918,7 @@ public final class DateTimeFormatterBuilder {
|
|||
}
|
||||
long value = getValue(context, valueLong);
|
||||
DecimalStyle decimalStyle = context.getDecimalStyle();
|
||||
int size = stringSize(value);
|
||||
int size = DecimalDigits.stringSize(value);
|
||||
if (value < 0) {
|
||||
size--;
|
||||
}
|
||||
|
@ -3369,17 +3353,6 @@ public final class DateTimeFormatterBuilder {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Simplified variant of Integer.stringSize that assumes positive values
|
||||
private static int stringSize(int x) {
|
||||
int p = 10;
|
||||
for (int i = 1; i < 10; i++) {
|
||||
if (x < p)
|
||||
return i;
|
||||
p = 10 * p;
|
||||
}
|
||||
return 10;
|
||||
}
|
||||
|
||||
private static final int[] TENS = new int[] {
|
||||
1,
|
||||
10,
|
||||
|
@ -3400,7 +3373,7 @@ public final class DateTimeFormatterBuilder {
|
|||
}
|
||||
int val = field.range().checkValidIntValue(value, field);
|
||||
DecimalStyle decimalStyle = context.getDecimalStyle();
|
||||
int stringSize = stringSize(val);
|
||||
int stringSize = DecimalDigits.stringSize(val);
|
||||
char zero = decimalStyle.getZeroDigit();
|
||||
if (val == 0 || stringSize < 10 - maxWidth) {
|
||||
// 0 or would round down to 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue