ICU-21174 Drop MaybeStackVector::appendAll because it requires copy constructor

This commit is contained in:
Hugo van der Merwe 2020-09-05 13:54:36 +02:00
parent b066f65a50
commit 8e04bf016d
3 changed files with 25 additions and 23 deletions

View file

@ -826,19 +826,6 @@ public:
T* operator[](ptrdiff_t i) {
return this->fPool[i];
}
/**
* Append copies of all the items from another MaybeStackVector to this one.
*/
void appendAll(const MaybeStackVector& other, UErrorCode& status) {
for (int32_t i = 0; i < other.fCount; i++) {
T* item = emplaceBack(*other[i]);
if (!item) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
}
}
};

View file

@ -2390,6 +2390,20 @@ int32_t MeasureUnit::getOffset() const {
return gOffsets[fTypeId] + fSubTypeId;
}
MeasureUnitImpl MeasureUnitImpl::copy(UErrorCode &status) const {
MeasureUnitImpl result;
result.complexity = complexity;
result.identifier.append(identifier, status);
for (int32_t i = 0; i < units.length(); i++) {
SingleUnitImpl *item = result.units.emplaceBack(*units[i]);
if (!item) {
status = U_MEMORY_ALLOCATION_ERROR;
return result;
}
}
return result;
}
U_NAMESPACE_END
#endif /* !UNCONFIG_NO_FORMATTING */

View file

@ -22,7 +22,7 @@ static const char kDefaultCurrency8[] = "XXX";
/**
* A struct representing a single unit (optional SI prefix and dimensionality).
*/
struct SingleUnitImpl : public UMemory {
struct U_I18N_API SingleUnitImpl : public UMemory {
/**
* Gets a single unit from the MeasureUnit. If there are multiple single units, sets an error
* code and returns the base dimensionless unit. Parses if necessary.
@ -120,12 +120,20 @@ struct SingleUnitImpl : public UMemory {
int32_t dimensionality = 1;
};
// Export explicit template instantiations of MaybeStackArray, MemoryPool and
// MaybeStackVector. This is required when building DLLs for Windows. (See
// datefmt.h, collationiterator.h, erarules.h and others for similar examples.)
#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
template class U_I18N_API MaybeStackArray<SingleUnitImpl*, 8>;
template class U_I18N_API MemoryPool<SingleUnitImpl, 8>;
template class U_I18N_API MaybeStackVector<SingleUnitImpl, 8>;
#endif
/**
* Internal representation of measurement units. Capable of representing all complexities of units,
* including mixed and compound units.
*/
struct MeasureUnitImpl : public UMemory {
struct U_I18N_API MeasureUnitImpl : public UMemory {
/** Extract the MeasureUnitImpl from a MeasureUnit. */
static inline const MeasureUnitImpl* get(const MeasureUnit& measureUnit) {
return measureUnit.fImpl;
@ -179,13 +187,7 @@ struct MeasureUnitImpl : public UMemory {
/**
* Create a copy of this MeasureUnitImpl. Don't use copy constructor to make this explicit.
*/
inline MeasureUnitImpl copy(UErrorCode& status) const {
MeasureUnitImpl result;
result.complexity = complexity;
result.units.appendAll(units, status);
result.identifier.append(identifier, status);
return result;
}
MeasureUnitImpl copy(UErrorCode& status) const;
/** Mutates this MeasureUnitImpl to take the reciprocal. */
void takeReciprocal(UErrorCode& status);
@ -216,7 +218,6 @@ struct MeasureUnitImpl : public UMemory {
CharString identifier;
};
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */