diff --git a/icu4c/source/common/cmemory.h b/icu4c/source/common/cmemory.h index a570d535bea..bc1c91c1500 100644 --- a/icu4c/source/common/cmemory.h +++ b/icu4c/source/common/cmemory.h @@ -285,7 +285,7 @@ inline T *LocalMemory::allocateInsteadAndCopy(int32_t newCapacity, int32_t le * * WARNING: MaybeStackArray only works with primitive (plain-old data) types. * It does NOT know how to call a destructor! If you work with classes with - * destructors, consider LocalArray in localpointer.h. + * destructors, consider LocalArray in localpointer.h or MemoryPool. */ template class MaybeStackArray { @@ -692,9 +692,8 @@ inline H *MaybeStackHeaderAndArray::orphanOrClone(int32_t l * * It doesn't do anything more than that, and is intentionally kept minimalist. */ -template +template class MemoryPool : public UMemory { - enum { STACK_CAPACITY = 8 }; public: MemoryPool() : count(0), pool() {} @@ -730,7 +729,7 @@ public: T* create(Args&&... args) { int32_t capacity = pool.getCapacity(); if (count == capacity && - pool.resize(capacity == STACK_CAPACITY ? 32 : 2 * capacity, + pool.resize(capacity == stackCapacity ? 4 * capacity : 2 * capacity, capacity) == nullptr) { return nullptr; } @@ -739,7 +738,7 @@ public: private: int32_t count; - MaybeStackArray pool; + MaybeStackArray pool; }; U_NAMESPACE_END diff --git a/icu4c/source/i18n/numparse_affixes.h b/icu4c/source/i18n/numparse_affixes.h index 4f58b3a4dcd..8b693624fa5 100644 --- a/icu4c/source/i18n/numparse_affixes.h +++ b/icu4c/source/i18n/numparse_affixes.h @@ -47,13 +47,14 @@ class CodePointMatcher : public NumberParseMatcher, public UMemory { } // namespace impl } // namespace numparse -// Export a explicit template instantiations of MaybeStackArray and CompactUnicodeString. +// Export a explicit template instantiations of MaybeStackArray, MemoryPool and CompactUnicodeString. // When building DLLs for Windows this is required even though no direct access leaks out of the i18n library. // (See digitlst.h, pluralaffix.h, datefmt.h, and others for similar examples.) -// Note: These need to be outside of the impl::numparse namespace, or Clang will generate a compile error. +// Note: These need to be outside of the numparse::impl namespace, or Clang will generate a compile error. #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN +template class U_I18N_API MaybeStackArray; template class U_I18N_API MaybeStackArray; -template class U_I18N_API MaybeStackArray; +template class U_I18N_API MemoryPool; template class U_I18N_API numparse::impl::CompactUnicodeString<4>; #endif