From b8d2d92d362f29ac762786a7a52cac4f48db4f58 Mon Sep 17 00:00:00 2001 From: Fredrik Roubert Date: Mon, 29 Oct 2018 22:12:00 +0100 Subject: [PATCH] ICU-20202 Replace CharStringPool with MemoryPool. The shared templated helper class MemoryPool is a drop-in replacement for the local helper class CharStringPool, with a simpler implementation and an interface that allows parameters to be passed to the constructor. --- icu4c/source/common/uloc_tag.cpp | 47 ++------------------------------ 1 file changed, 3 insertions(+), 44 deletions(-) diff --git a/icu4c/source/common/uloc_tag.cpp b/icu4c/source/common/uloc_tag.cpp index 8146ec3077a..89702968cd7 100644 --- a/icu4c/source/common/uloc_tag.cpp +++ b/icu4c/source/common/uloc_tag.cpp @@ -19,7 +19,6 @@ #include "putilimp.h" #include "uinvchar.h" #include "ulocimp.h" -#include "uvector.h" #include "uassert.h" @@ -348,46 +347,6 @@ static const char* ultag_getGrandfathered(const ULanguageTag* langtag); #endif -namespace { - -// Helper class to memory manage CharString objects. -// Only ever stack-allocated, does not need to inherit UMemory. -class CharStringPool { -public: - CharStringPool() : status(U_ZERO_ERROR), pool(&deleter, nullptr, status) {} - ~CharStringPool() = default; - - CharStringPool(const CharStringPool&) = delete; - CharStringPool& operator=(const CharStringPool&) = delete; - - icu::CharString* create() { - if (U_FAILURE(status)) { - return nullptr; - } - icu::CharString* const obj = new icu::CharString; - if (obj == nullptr) { - status = U_MEMORY_ALLOCATION_ERROR; - return nullptr; - } - pool.addElement(obj, status); - if (U_FAILURE(status)) { - delete obj; - return nullptr; - } - return obj; - } - -private: - static void U_CALLCONV deleter(void* obj) { - delete static_cast(obj); - } - - UErrorCode status; - icu::UVector pool; -}; - -} // namespace - /* * ------------------------------------------------- * @@ -1105,7 +1064,7 @@ _appendKeywordsToLanguageTag(const char* localeID, icu::ByteSink& sink, UBool st AttributeListEntry *firstAttr = NULL; AttributeListEntry *attr; char *attrValue; - CharStringPool extBufPool; + icu::MemoryPool extBufPool; const char *bcpKey=nullptr, *bcpValue=nullptr; UErrorCode tmpStatus = U_ZERO_ERROR; int32_t keylen; @@ -1285,12 +1244,12 @@ _appendKeywordsToLanguageTag(const char* localeID, icu::ByteSink& sink, UBool st } } bcpKey = key; - icu::CharString* extBuf = extBufPool.create(); + icu::CharString* extBuf = + extBufPool.create(buf.data(), len, tmpStatus); if (extBuf == nullptr) { *status = U_MEMORY_ALLOCATION_ERROR; break; } - extBuf->append(buf.data(), len, tmpStatus); if (U_FAILURE(tmpStatus)) { *status = tmpStatus; break;