ICU-13177 Reverting changes that were accidentally committed to branch in r40120

X-SVN-Rev: 40201
This commit is contained in:
Shane Carr 2017-06-23 07:29:54 +00:00
parent 0c193f20f5
commit b492e597f0
3 changed files with 83 additions and 139 deletions

View File

@ -24,7 +24,6 @@
#include "nfrlist.h" #include "nfrlist.h"
#include "patternprops.h" #include "patternprops.h"
#include "putilimp.h" #include "putilimp.h"
#include "uassert.h"
#ifdef RBNF_DEBUG #ifdef RBNF_DEBUG
#include "cmemory.h" #include "cmemory.h"
@ -837,18 +836,11 @@ uint64_t util64_pow(uint32_t base, uint16_t exponent) {
} }
uint64_t result = 1; uint64_t result = 1;
uint64_t pow = base; uint64_t pow = base;
UBool safe = TRUE;
while (exponent > 0) { while (exponent > 0) {
U_ASSERT(safe);
if ((exponent & 1) == 1) { if ((exponent & 1) == 1) {
result *= pow; result *= pow;
} }
if (pow >= 0x100000000L) { pow *= pow;
// The next step will push us out of bounds
safe = FALSE;
} else {
pow *= pow;
}
exponent >>= 1; exponent >>= 1;
} }
return result; return result;

View File

@ -90,167 +90,121 @@ public class PositiveDecimalFormat implements Format.TargetFormat {
|| properties.getMaximumFractionDigits() != 0; || properties.getMaximumFractionDigits() != 0;
} }
private static class ParameterStruct { // Properties
private final boolean alwaysShowDecimal;
private final int primaryGroupingSize;
private final int secondaryGroupingSize;
private final int minimumGroupingDigits;
// Properties // Symbols
boolean alwaysShowDecimal; private final String infinityString;
int primaryGroupingSize; private final String nanString;
int secondaryGroupingSize; private final String groupingSeparator;
int minimumGroupingDigits; private final String decimalSeparator;
private final String[] digitStrings;
// Symbols private final int codePointZero;
String infinityString;
String nanString;
String groupingSeparator;
String decimalSeparator;
String[] digitStrings;
int codePointZero;
void setProperties(DecimalFormatSymbols symbols, IProperties properties) {
int _primary = properties.getGroupingSize();
int _secondary = properties.getSecondaryGroupingSize();
primaryGroupingSize = _primary > 0 ? _primary : _secondary > 0 ? _secondary : 0;
secondaryGroupingSize = _secondary > 0 ? _secondary : primaryGroupingSize;
minimumGroupingDigits = properties.getMinimumGroupingDigits();
alwaysShowDecimal = properties.getDecimalSeparatorAlwaysShown();
infinityString = symbols.getInfinity();
nanString = symbols.getNaN();
if (CurrencyFormat.useCurrency(properties)) {
groupingSeparator = symbols.getMonetaryGroupingSeparatorString();
decimalSeparator = symbols.getMonetaryDecimalSeparatorString();
} else {
groupingSeparator = symbols.getGroupingSeparatorString();
decimalSeparator = symbols.getDecimalSeparatorString();
}
// Check to see if we can use code points instead of strings
int _codePointZero = symbols.getCodePointZero();
if (_codePointZero != -1) {
// Fast Path (9-25% faster than slow path when formatting long strings)
digitStrings = null;
codePointZero = _codePointZero;
} else {
// Slow Path
digitStrings = symbols.getDigitStrings(); // makes a copy
codePointZero = -1;
}
}
}
private static class TransientStruct {
FormatQuantity input;
NumberStringBuilder string;
int index;
ParameterStruct params;
}
private final ParameterStruct params;
public PositiveDecimalFormat(DecimalFormatSymbols symbols, IProperties properties) { public PositiveDecimalFormat(DecimalFormatSymbols symbols, IProperties properties) {
params = new ParameterStruct(); int _primary = properties.getGroupingSize();
params.setProperties(symbols, properties); int _secondary = properties.getSecondaryGroupingSize();
primaryGroupingSize = _primary > 0 ? _primary : _secondary > 0 ? _secondary : 0;
secondaryGroupingSize = _secondary > 0 ? _secondary : primaryGroupingSize;
minimumGroupingDigits = properties.getMinimumGroupingDigits();
alwaysShowDecimal = properties.getDecimalSeparatorAlwaysShown();
infinityString = symbols.getInfinity();
nanString = symbols.getNaN();
if (CurrencyFormat.useCurrency(properties)) {
groupingSeparator = symbols.getMonetaryGroupingSeparatorString();
decimalSeparator = symbols.getMonetaryDecimalSeparatorString();
} else {
groupingSeparator = symbols.getGroupingSeparatorString();
decimalSeparator = symbols.getDecimalSeparatorString();
}
// Check to see if we can use code points instead of strings
int _codePointZero = symbols.getCodePointZero();
if (_codePointZero != -1) {
// Fast Path (~9% faster than slow path when formatting long strings)
digitStrings = null;
codePointZero = _codePointZero;
} else {
// Slow Path
digitStrings = symbols.getDigitStrings(); // makes a copy
codePointZero = -1;
}
} }
// private static void apply(
// FormatQuantity input,
// NumberStringBuilder string,
// int startIndex,
// DecimalFormatSymbols symbols,
// IProperties properties) {
//
// }
private static final ThreadLocal<TransientStruct> threadLocalTransientStruct =
new ThreadLocal<TransientStruct>() {
@Override
protected TransientStruct initialValue() {
return new TransientStruct();
}
};
private static final TransientStruct staticTransientStruct = new TransientStruct();
@Override @Override
public int target(FormatQuantity input, NumberStringBuilder string, int startIndex) { public int target(FormatQuantity input, NumberStringBuilder string, int startIndex) {
// TransientStruct trans = staticTransientStruct; int length = 0;
TransientStruct trans = threadLocalTransientStruct.get();
trans.input = input;
trans.string = string;
trans.index = startIndex;
trans.params = params;
target(trans);
return trans.index - startIndex;
}
private static void target(TransientStruct trans) { if (input.isInfinite()) {
if (trans.input.isInfinite()) { length += string.insert(startIndex, infinityString, NumberFormat.Field.INTEGER);
trans.index +=
trans.string.insert(trans.index, trans.params.infinityString, NumberFormat.Field.INTEGER);
} else if (trans.input.isNaN()) { } else if (input.isNaN()) {
trans.index += length += string.insert(startIndex, nanString, NumberFormat.Field.INTEGER);
trans.string.insert(trans.index, trans.params.nanString, NumberFormat.Field.INTEGER);
} else { } else {
// Add the integer digits // Add the integer digits
trans.index += addIntegerDigits(trans); length += addIntegerDigits(input, string, startIndex);
// Add the decimal point // Add the decimal point
if (trans.input.getLowerDisplayMagnitude() < 0 || trans.params.alwaysShowDecimal) { if (input.getLowerDisplayMagnitude() < 0 || alwaysShowDecimal) {
trans.index += length +=
trans.string.insert( string.insert(
trans.index, trans.params.decimalSeparator, NumberFormat.Field.DECIMAL_SEPARATOR); startIndex + length, decimalSeparator, NumberFormat.Field.DECIMAL_SEPARATOR);
} }
// Add the fraction digits // Add the fraction digits
trans.index += addFractionDigits(trans); length += addFractionDigits(input, string, startIndex + length);
} }
return length;
} }
private static int addIntegerDigits(TransientStruct trans) { private int addIntegerDigits(FormatQuantity input, NumberStringBuilder string, int startIndex) {
int length = 0; int length = 0;
int integerCount = trans.input.getUpperDisplayMagnitude() + 1; int integerCount = input.getUpperDisplayMagnitude() + 1;
for (int i = 0; i < integerCount; i++) { for (int i = 0; i < integerCount; i++) {
// Add grouping separator // Add grouping separator
if (trans.params.primaryGroupingSize > 0 if (primaryGroupingSize > 0
&& i == trans.params.primaryGroupingSize && i == primaryGroupingSize
&& integerCount - i >= trans.params.minimumGroupingDigits) { && integerCount - i >= minimumGroupingDigits) {
length += length +=
trans.string.insert( string.insert(startIndex, groupingSeparator, NumberFormat.Field.GROUPING_SEPARATOR);
trans.index, trans.params.groupingSeparator, NumberFormat.Field.GROUPING_SEPARATOR); } else if (secondaryGroupingSize > 0
} else if (trans.params.secondaryGroupingSize > 0 && i > primaryGroupingSize
&& i > trans.params.primaryGroupingSize && (i - primaryGroupingSize) % secondaryGroupingSize == 0) {
&& (i - trans.params.primaryGroupingSize) % trans.params.secondaryGroupingSize == 0) {
length += length +=
trans.string.insert( string.insert(startIndex, groupingSeparator, NumberFormat.Field.GROUPING_SEPARATOR);
trans.index, trans.params.groupingSeparator, NumberFormat.Field.GROUPING_SEPARATOR);
} }
// Get and append the next digit value // Get and append the next digit value
byte nextDigit = trans.input.getDigit(i); byte nextDigit = input.getDigit(i);
length += addDigit(nextDigit, trans.index, NumberFormat.Field.INTEGER, trans); length += addDigit(nextDigit, string, startIndex, NumberFormat.Field.INTEGER);
} }
return length; return length;
} }
private static int addFractionDigits(TransientStruct trans) { private int addFractionDigits(FormatQuantity input, NumberStringBuilder string, int index) {
int length = 0; int length = 0;
int fractionCount = -trans.input.getLowerDisplayMagnitude(); int fractionCount = -input.getLowerDisplayMagnitude();
for (int i = 0; i < fractionCount; i++) { for (int i = 0; i < fractionCount; i++) {
// Get and append the next digit value // Get and append the next digit value
byte nextDigit = trans.input.getDigit(-i - 1); byte nextDigit = input.getDigit(-i - 1);
length += addDigit(nextDigit, trans.index + length, NumberFormat.Field.FRACTION, trans); length += addDigit(nextDigit, string, index + length, NumberFormat.Field.FRACTION);
} }
return length; return length;
} }
private static int addDigit(byte digit, int index, Field field, TransientStruct trans) { private int addDigit(byte digit, NumberStringBuilder outputString, int index, Field field) {
if (trans.params.codePointZero != -1) { if (codePointZero != -1) {
return trans.string.insertCodePoint(index, trans.params.codePointZero + digit, field); return outputString.insertCodePoint(index, codePointZero + digit, field);
} else { } else {
return trans.string.insert(index, trans.params.digitStrings[digit], field); return outputString.insert(index, digitStrings[digit], field);
} }
} }
@ -258,13 +212,11 @@ public class PositiveDecimalFormat implements Format.TargetFormat {
public void export(Properties properties) { public void export(Properties properties) {
// For backwards compatibility, export 0 as secondary grouping if primary and secondary are the same // For backwards compatibility, export 0 as secondary grouping if primary and secondary are the same
int effectiveSecondaryGroupingSize = int effectiveSecondaryGroupingSize =
params.secondaryGroupingSize == params.primaryGroupingSize secondaryGroupingSize == primaryGroupingSize ? 0 : secondaryGroupingSize;
? 0
: params.secondaryGroupingSize;
properties.setDecimalSeparatorAlwaysShown(params.alwaysShowDecimal); properties.setDecimalSeparatorAlwaysShown(alwaysShowDecimal);
properties.setGroupingSize(params.primaryGroupingSize); properties.setGroupingSize(primaryGroupingSize);
properties.setSecondaryGroupingSize(effectiveSecondaryGroupingSize); properties.setSecondaryGroupingSize(effectiveSecondaryGroupingSize);
properties.setMinimumGroupingDigits(params.minimumGroupingDigits); properties.setMinimumGroupingDigits(minimumGroupingDigits);
} }
} }

View File

@ -1590,7 +1590,7 @@ public final class Normalizer implements Cloneable {
* <tt>String</tt> over which this <tt>Normalizer</tt> is iterating * <tt>String</tt> over which this <tt>Normalizer</tt> is iterating
* @deprecated ICU 2.2. Use startIndex() instead. * @deprecated ICU 2.2. Use startIndex() instead.
* @return The codepoint as an int * @return The codepoint as an int
* @see #index * @see #startIndex
*/ */
@Deprecated @Deprecated
public int getBeginIndex() { public int getBeginIndex() {