From 027c60bf5698cfcf480f642183e4876a0be2384d Mon Sep 17 00:00:00 2001 From: Hugo van der Merwe <17109322+hugovdm@users.noreply.github.com> Date: Tue, 28 Apr 2020 21:55:19 +0200 Subject: [PATCH] Post-merge: update code to make "make check" pass. * MaybeStackVector -> ConversionRates. * Inherit from UMemory to make MaybeStackVector happy (UnitConverter and ConverterPreference). * Hack around getUnitsData's bad interface. Code is still bad though, unit tests don't cover everything: * getUnitsData does not work correctly, and various things are marked with "WIP" comments (Work In Progress). --- icu4c/source/i18n/complexunitsconverter.cpp | 6 ++---- icu4c/source/i18n/complexunitsconverter.h | 4 ++-- icu4c/source/i18n/unitconverter.cpp | 4 ++-- icu4c/source/i18n/unitconverter.h | 2 +- icu4c/source/i18n/unitsrouter.cpp | 7 +++++-- icu4c/source/i18n/unitsrouter.h | 4 ++-- icu4c/source/test/intltest/unitstest.cpp | 6 ++---- 7 files changed, 16 insertions(+), 17 deletions(-) diff --git a/icu4c/source/i18n/complexunitsconverter.cpp b/icu4c/source/i18n/complexunitsconverter.cpp index 1b6389b5953..b5eca8e1c69 100644 --- a/icu4c/source/i18n/complexunitsconverter.cpp +++ b/icu4c/source/i18n/complexunitsconverter.cpp @@ -15,8 +15,7 @@ U_NAMESPACE_BEGIN ComplexUnitsConverter::ComplexUnitsConverter(const MeasureUnit inputUnit, const MeasureUnit outputUnits, - const MaybeStackVector &ratesInfo, - UErrorCode &status) { + const ConversionRates &ratesInfo, UErrorCode &status) { int32_t length; auto singleUnits = outputUnits.splitToSingleUnits(length, status); MaybeStackVector singleUnitsInOrder; @@ -30,8 +29,7 @@ ComplexUnitsConverter::ComplexUnitsConverter(const MeasureUnit inputUnit, const ComplexUnitsConverter::ComplexUnitsConverter(const MeasureUnit inputUnit, const MaybeStackVector outputUnits, - const MaybeStackVector &ratesInfo, - UErrorCode &status) { + const ConversionRates &ratesInfo, UErrorCode &status) { if (outputUnits.length() == 0) { status = U_ILLEGAL_ARGUMENT_ERROR; return; diff --git a/icu4c/source/i18n/complexunitsconverter.h b/icu4c/source/i18n/complexunitsconverter.h index d021ed9cc3a..3b71689416f 100644 --- a/icu4c/source/i18n/complexunitsconverter.h +++ b/icu4c/source/i18n/complexunitsconverter.h @@ -31,10 +31,10 @@ class U_I18N_API ComplexUnitsConverter { * @param status */ ComplexUnitsConverter(const MeasureUnit inputUnit, const MaybeStackVector outputUnits, - const MaybeStackVector &ratesInfo, UErrorCode &status); + const ConversionRates &ratesInfo, UErrorCode &status); ComplexUnitsConverter(const MeasureUnit inputUnit, const MeasureUnit outputUnits, - const MaybeStackVector &ratesInfo, UErrorCode &status); + const ConversionRates &ratesInfo, UErrorCode &status); // Returns true if the `quantity` in the `inputUnit` is greater than or equal than the `limit` in the // biggest `outputUnits` diff --git a/icu4c/source/i18n/unitconverter.cpp b/icu4c/source/i18n/unitconverter.cpp index 5e3e76fa5c6..85b82521dbb 100644 --- a/icu4c/source/i18n/unitconverter.cpp +++ b/icu4c/source/i18n/unitconverter.cpp @@ -268,7 +268,7 @@ void addFactorElement(Factor &factor, StringPiece elementStr, SigNum sigNum) { /* * Extracts `Factor` from a complete string factor. e.g. "ft2m^3*1007/cup2m3*3" * - * TODO: unused parameter 'status' [-Wunused-parameter] + * TODO: warning: unused parameter 'status' [-Wunused-parameter] */ Factor extractFactorConversions(StringPiece stringFactor, UErrorCode &status) { Factor result; @@ -343,7 +343,7 @@ void substituteSingleConstant(int32_t constantPower, } } -// TODO: unused parameter 'status' [-Wunused-parameter] +// TODO: warning: unused parameter 'status' [-Wunused-parameter] void substituteConstants(Factor &factor, UErrorCode &status) { double constantsValues[CONSTANTS_COUNT]; diff --git a/icu4c/source/i18n/unitconverter.h b/icu4c/source/i18n/unitconverter.h index 62d9582f4ec..272de4ca50b 100644 --- a/icu4c/source/i18n/unitconverter.h +++ b/icu4c/source/i18n/unitconverter.h @@ -42,7 +42,7 @@ UnitsConvertibilityState U_I18N_API checkConvertibility(const MeasureUnit &sourc /** * Converts from a source `MeasureUnit` to a target `MeasureUnit`. */ -class U_I18N_API UnitConverter { +class U_I18N_API UnitConverter : public UMemory { public: /** * Constructor of `UnitConverter`. diff --git a/icu4c/source/i18n/unitsrouter.cpp b/icu4c/source/i18n/unitsrouter.cpp index 62e59c8e2ad..5ca1347aeda 100644 --- a/icu4c/source/i18n/unitsrouter.cpp +++ b/icu4c/source/i18n/unitsrouter.cpp @@ -25,9 +25,12 @@ UnitsRouter::UnitsRouter(MeasureUnit inputUnit, StringPiece locale, StringPiece const char *region = "001"; // FIXME extract from locale. CharString category; MeasureUnit baseUnit; - MaybeStackVector conversionRates; + ConversionRates conversionRates(status); + + // WIP/TODO(hugovdm): drop tmpConversionRates, redo getUnitsData. + MaybeStackVector tmpConversionRates; MaybeStackVector unitPreferences; - getUnitsData(region, usage.data(), inputUnit, category, baseUnit, conversionRates, unitPreferences, + getUnitsData(region, usage.data(), inputUnit, category, baseUnit, tmpConversionRates, unitPreferences, status); for (int i = 0, n = unitPreferences.length(); i < n; ++i) { diff --git a/icu4c/source/i18n/unitsrouter.h b/icu4c/source/i18n/unitsrouter.h index 0b25c63c119..9e38f150569 100644 --- a/icu4c/source/i18n/unitsrouter.h +++ b/icu4c/source/i18n/unitsrouter.h @@ -18,12 +18,12 @@ U_NAMESPACE_BEGIN -struct ConverterPreference { +struct ConverterPreference : UMemory { ComplexUnitsConverter converter; double limit; ConverterPreference(MeasureUnit source, MeasureUnit complexTarget, double limit, - const MaybeStackVector &ratesInfo, UErrorCode &status) + const ConversionRates &ratesInfo, UErrorCode &status) : converter(source, complexTarget, ratesInfo, status), limit(limit) {} }; diff --git a/icu4c/source/test/intltest/unitstest.cpp b/icu4c/source/test/intltest/unitstest.cpp index 1b92c12b664..247a89f59f8 100644 --- a/icu4c/source/test/intltest/unitstest.cpp +++ b/icu4c/source/test/intltest/unitstest.cpp @@ -157,10 +157,8 @@ void UnitsTest::verifyTestCase(const UnitConversionTestCase &testCase) { MeasureUnit sourceUnit = MeasureUnit::forIdentifier(testCase.source, status); MeasureUnit targetUnit = MeasureUnit::forIdentifier(testCase.target, status); - MaybeStackVector unitsInfos; - getAllConversionRates(unitsInfos, status); - - UnitConverter converter(sourceUnit, targetUnit, unitsInfos, status); + ConversionRates conversionRates(status); + UnitConverter converter(sourceUnit, targetUnit, conversionRates, status); double actual = converter.convert(testCase.inputValue); -- 2.40.0