From: Shane Carr Date: Wed, 23 May 2018 04:21:24 +0000 (+0000) Subject: ICU-13717 During SimpleDateFormat#parseInt, avoid cloning the DecimalFormat unless... X-Git-Tag: release-62-rc~58^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0c8fed6bde6afb38b03d67f322d2414b83a3229a;p=icu ICU-13717 During SimpleDateFormat#parseInt, avoid cloning the DecimalFormat unless necessary. X-SVN-Rev: 41440 --- diff --git a/icu4c/source/i18n/smpdtfmt.cpp b/icu4c/source/i18n/smpdtfmt.cpp index 210e7db1a29..b1b90882fce 100644 --- a/icu4c/source/i18n/smpdtfmt.cpp +++ b/icu4c/source/i18n/smpdtfmt.cpp @@ -3754,21 +3754,19 @@ void SimpleDateFormat::parseInt(const UnicodeString& text, UBool allowNegative, const NumberFormat *fmt) const { UnicodeString oldPrefix; - const DecimalFormat* fmtAsDF = dynamic_cast(fmt); + auto* fmtAsDF = dynamic_cast(fmt); LocalPointer df; - if (fmtAsDF != nullptr) { + if (!allowNegative && fmtAsDF != nullptr) { df.adoptInstead(dynamic_cast(fmtAsDF->clone())); - } - if (!allowNegative && !df.isNull()) { - fmt = df.getAlias(); - df->getNegativePrefix(oldPrefix); + if (df.isNull()) { + // Memory allocation error + return; + } df->setNegativePrefix(UnicodeString(TRUE, SUPPRESS_NEGATIVE_PREFIX, -1)); + fmt = df.getAlias(); } int32_t oldPos = pos.getIndex(); fmt->parse(text, number, pos); - if (!df.isNull()) { - df->setNegativePrefix(oldPrefix); - } if (maxDigits > 0) { // adjust the result to fit into