utils::copyCurrencyCode(fCurrencyCode, currencySymbols.getIsoCode());
// TODO: Figure out how to make this faster and re-enable.
+ // Computing the "lead code points" set for fastpathing is too slow to use in production.
+ // See http://bugs.icu-project.org/trac/ticket/13584
// // Compute the full set of characters that could be the first in a currency to allow for
// // efficient smoke test.
// fLeadCodePoints.add(fCurrency1.char32At(0));
// fLeadCodePoints.freeze();
}
-bool CombinedCurrencyMatcher::match(StringSegment& segment, ParsedNumber& result,
- UErrorCode& status) const {
+bool
+CombinedCurrencyMatcher::match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const {
if (result.currencyCode[0] != 0) {
return false;
}
// Locale has a non-trivial default constructor.
CharString fLocaleName;
- UnicodeSet fLeadCodePoints;
+ // TODO: See comments in constructor in numparse_currency.cpp
+ // UnicodeSet fLeadCodePoints;
/** Matches the currency string without concern for currency spacing. */
bool matchCurrency(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const;
import com.ibm.icu.impl.StringSegment;
import com.ibm.icu.impl.TextTrieMap;
import com.ibm.icu.text.DecimalFormatSymbols;
-import com.ibm.icu.text.UnicodeSet;
import com.ibm.icu.util.Currency;
import com.ibm.icu.util.Currency.CurrencyStringInfo;
private final TextTrieMap<CurrencyStringInfo> longNameTrie;
private final TextTrieMap<CurrencyStringInfo> symbolTrie;
- private final UnicodeSet leadCodePoints;
+ // TODO: See comments in constructor.
+ // private final UnicodeSet leadCodePoints;
public static CombinedCurrencyMatcher getInstance(Currency currency, DecimalFormatSymbols dfs) {
// TODO: Cache these instances. They are somewhat expensive.
this.currency1 = currency.getSymbol(dfs.getULocale());
this.currency2 = currency.getCurrencyCode();
- afterPrefixInsert = dfs
- .getPatternForCurrencySpacing(DecimalFormatSymbols.CURRENCY_SPC_INSERT, false);
- beforeSuffixInsert = dfs
- .getPatternForCurrencySpacing(DecimalFormatSymbols.CURRENCY_SPC_INSERT, true);
+ afterPrefixInsert = dfs.getPatternForCurrencySpacing(DecimalFormatSymbols.CURRENCY_SPC_INSERT,
+ false);
+ beforeSuffixInsert = dfs.getPatternForCurrencySpacing(DecimalFormatSymbols.CURRENCY_SPC_INSERT,
+ true);
// TODO: Currency trie does not currently have an option for case folding. It defaults to use
// case folding on long-names but not symbols.
longNameTrie = Currency.getParsingTrie(dfs.getULocale(), Currency.LONG_NAME);
symbolTrie = Currency.getParsingTrie(dfs.getULocale(), Currency.SYMBOL_NAME);
- // Compute the full set of characters that could be the first in a currency to allow for
- // efficient smoke test.
- leadCodePoints = new UnicodeSet();
- leadCodePoints.add(currency1.codePointAt(0));
- leadCodePoints.add(currency2.codePointAt(0));
- leadCodePoints.add(beforeSuffixInsert.codePointAt(0));
- longNameTrie.putLeadCodePoints(leadCodePoints);
- symbolTrie.putLeadCodePoints(leadCodePoints);
- // Always apply case mapping closure for currencies
- leadCodePoints.closeOver(UnicodeSet.ADD_CASE_MAPPINGS);
- leadCodePoints.freeze();
+ // TODO: Figure out how to make this faster and re-enable.
+ // Computing the "lead code points" set for fastpathing is too slow to use in production.
+ // See http://bugs.icu-project.org/trac/ticket/13584
+ // // Compute the full set of characters that could be the first in a currency to allow for
+ // // efficient smoke test.
+ // leadCodePoints = new UnicodeSet();
+ // leadCodePoints.add(currency1.codePointAt(0));
+ // leadCodePoints.add(currency2.codePointAt(0));
+ // leadCodePoints.add(beforeSuffixInsert.codePointAt(0));
+ // longNameTrie.putLeadCodePoints(leadCodePoints);
+ // symbolTrie.putLeadCodePoints(leadCodePoints);
+ // // Always apply case mapping closure for currencies
+ // leadCodePoints.closeOver(UnicodeSet.ADD_CASE_MAPPINGS);
+ // leadCodePoints.freeze();
}
@Override
@Override
public boolean smokeTest(StringSegment segment) {
- return segment.startsWith(leadCodePoints);
+ // TODO: See constructor
+ return true;
+ // return segment.startsWith(leadCodePoints);
}
@Override
transient volatile DecimalFormatProperties exportedProperties;
transient volatile NumberParserImpl parser;
- transient volatile NumberParserImpl parserWithCurrency;
+ transient volatile NumberParserImpl currencyParser;
//=====================================================================================//
// CONSTRUCTORS //
// Note: if this is a currency instance, currencies will be matched despite the fact that we are not in the
// parseCurrency method (backwards compatibility)
int startIndex = parsePosition.getIndex();
+ NumberParserImpl parser = getParser();
parser.parse(text, startIndex, true, result);
if (result.success()) {
parsePosition.setIndex(result.charEnd);
ParsedNumber result = new ParsedNumber();
int startIndex = parsePosition.getIndex();
- parserWithCurrency.parse(text.toString(), startIndex, true, result);
+ NumberParserImpl parser = getCurrencyParser();
+ parser.parse(text.toString(), startIndex, true, result);
if (result.success()) {
parsePosition.setIndex(result.charEnd);
// TODO: Accessing properties here is technically not thread-safe
- Number number = result.getNumber(parserWithCurrency.getParseFlags());
+ Number number = result.getNumber(parser.getParseFlags());
// Backwards compatibility: return com.ibm.icu.math.BigDecimal
if (number instanceof java.math.BigDecimal) {
number = safeConvertBigDecimal((java.math.BigDecimal) number);
}
assert locale != null;
formatter = NumberFormatter.fromDecimalFormat(properties, symbols, exportedProperties).locale(locale);
- parser = NumberParserImpl.createParserFromProperties(properties, symbols, false);
- parserWithCurrency = NumberParserImpl.createParserFromProperties(properties, symbols, true);
+
+ // Lazy-initialize the parsers only when we need them.
+ parser = null;
+ currencyParser = null;
+ }
+
+ NumberParserImpl getParser() {
+ if (parser == null) {
+ parser = NumberParserImpl.createParserFromProperties(properties, symbols, false);
+ }
+ return parser;
+ }
+
+ NumberParserImpl getCurrencyParser() {
+ if (currencyParser == null) {
+ currencyParser = NumberParserImpl.createParserFromProperties(properties, symbols, true);
+ }
+ return currencyParser;
}
/**