X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/f3c0d7a59d99c2a94c6b8822291f0e42be3773c9..HEAD:/icuSources/i18n/nfrs.cpp diff --git a/icuSources/i18n/nfrs.cpp b/icuSources/i18n/nfrs.cpp index 129b0b32..e26f08be 100644 --- a/icuSources/i18n/nfrs.cpp +++ b/icuSources/i18n/nfrs.cpp @@ -681,7 +681,7 @@ static void dumpUS(FILE* f, const UnicodeString& us) { #endif UBool -NFRuleSet::parse(const UnicodeString& text, ParsePosition& pos, double upperBound, Formattable& result, UBool lenient) const +NFRuleSet::parse(const UnicodeString& text, ParsePosition& pos, double upperBound, uint32_t nonNumericalExecutedRuleMask, Formattable& result, UBool lenient) const { // try matching each rule in the rule set against the text being // parsed. Whichever one matches the most characters is the one @@ -707,9 +707,12 @@ NFRuleSet::parse(const UnicodeString& text, ParsePosition& pos, double upperBoun #endif // Try each of the negative rules, fraction rules, infinity rules and NaN rules for (int i = 0; i < NON_NUMERICAL_RULE_LENGTH; i++) { - if (nonNumericalRules[i]) { + if (nonNumericalRules[i] && ((nonNumericalExecutedRuleMask >> i) & 1) == 0) { + // Mark this rule as being executed so that we don't try to execute it again. + nonNumericalExecutedRuleMask |= 1 << i; + Formattable tempResult; - UBool success = nonNumericalRules[i]->doParse(text, workingPos, 0, upperBound, tempResult, lenient || isDecimalFormatRuleParseable() ); + UBool success = nonNumericalRules[i]->doParse(text, workingPos, 0, upperBound, nonNumericalExecutedRuleMask, tempResult, lenient || isDecimalFormatRuleParseable() ); if (success && (workingPos.getIndex() > highWaterMark.getIndex())) { result = tempResult; highWaterMark = workingPos; @@ -748,7 +751,7 @@ NFRuleSet::parse(const UnicodeString& text, ParsePosition& pos, double upperBoun continue; } Formattable tempResult; - UBool success = rules[i]->doParse(text, workingPos, fIsFractionRuleSet, upperBound, tempResult); + UBool success = rules[i]->doParse(text, workingPos, fIsFractionRuleSet, upperBound, nonNumericalExecutedRuleMask, tempResult); if (success && workingPos.getIndex() > highWaterMark.getIndex()) { result = tempResult; highWaterMark = workingPos; @@ -830,19 +833,22 @@ int64_t util64_fromDouble(double d) { return result; } -int64_t util64_pow(int32_t base, uint16_t exponent) { +uint64_t util64_pow(uint32_t base, uint16_t exponent) { if (base == 0) { return 0; } - int64_t result = 1; - int64_t pow = base; - while (exponent > 0) { - if ((exponent & 1) == 1) { - result *= pow; - } - pow *= pow; - exponent >>= 1; - } + uint64_t result = 1; + uint64_t pow = base; + while (true) { + if ((exponent & 1) == 1) { + result *= pow; + } + exponent >>= 1; + if (exponent == 0) { + break; + } + pow *= pow; + } return result; } @@ -1027,4 +1033,3 @@ U_NAMESPACE_END /* U_HAVE_RBNF */ #endif -