2 ******************************************************************************
3 * Copyright (C) 1996-2009, International Business Machines *
4 * Corporation and others. All Rights Reserved. *
5 ******************************************************************************
8 #include "unicode/utypes.h"
10 #if !UCONFIG_NO_COLLATION
12 #include "unicode/unistr.h"
13 #include "unicode/putil.h"
14 #include "unicode/usearch.h"
17 #include "unicode/coll.h"
18 #include "unicode/tblcoll.h"
19 #include "unicode/coleitr.h"
20 #include "unicode/ucoleitr.h"
22 #include "unicode/regex.h" // TODO: make conditional on regexp being built.
24 #include "unicode/uniset.h"
25 #include "unicode/uset.h"
26 #include "unicode/ustring.h"
33 #include "unicode/colldata.h"
37 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
38 #define NEW_ARRAY(type, count) (type *) uprv_malloc((count) * sizeof(type))
39 #define DELETE_ARRAY(array) uprv_free((void *) (array))
40 #define ARRAY_COPY(dst, src, count) uprv_memcpy((void *) (dst), (void *) (src), (count) * sizeof (src)[0])
42 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CEList
)
44 #ifdef INSTRUMENT_CELIST
45 int32_t CEList::_active
= 0;
46 int32_t CEList::_histogram
[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
49 CEList::CEList(UCollator
*coll
, const UnicodeString
&string
, UErrorCode
&status
)
50 : ces(NULL
), listMax(CELIST_BUFFER_SIZE
), listSize(0)
52 UCollationElements
*elems
= ucol_openElements(coll
, string
.getBuffer(), string
.length(), &status
);
53 UCollationStrength strength
= ucol_getStrength(coll
);
54 UBool toShift
= ucol_getAttribute(coll
, UCOL_ALTERNATE_HANDLING
, &status
) == UCOL_SHIFTED
;
55 uint32_t variableTop
= ucol_getVariableTop(coll
, &status
);
56 uint32_t strengthMask
= 0;
59 if (U_FAILURE(status
)) {
63 // **** only set flag if string has Han(gul) ****
64 ucol_forceHanImplicit(elems
, &status
);
69 strengthMask
|= UCOL_TERTIARYORDERMASK
;
73 strengthMask
|= UCOL_SECONDARYORDERMASK
;
77 strengthMask
|= UCOL_PRIMARYORDERMASK
;
80 #ifdef INSTRUMENT_CELIST
87 while ((order
= ucol_next(elems
, &status
)) != UCOL_NULLORDER
) {
88 UBool cont
= isContinuation(order
);
90 order
&= strengthMask
;
92 if (toShift
&& variableTop
> (uint32_t)order
&& (order
& UCOL_PRIMARYORDERMASK
) != 0) {
93 if (strength
>= UCOL_QUATERNARY
) {
94 order
&= UCOL_PRIMARYORDERMASK
;
96 order
= UCOL_IGNORABLE
;
100 if (order
== UCOL_IGNORABLE
) {
105 order
|= UCOL_CONTINUATION_MARKER
;
111 ucol_closeElements(elems
);
116 #ifdef INSTRUMENT_CELIST
120 if (ces
!= ceBuffer
) {
125 void CEList::add(uint32_t ce
, UErrorCode
&status
)
127 if (U_FAILURE(status
)) {
131 if (listSize
>= listMax
) {
132 int32_t newMax
= listMax
+ CELIST_BUFFER_SIZE
;
134 #ifdef INSTRUMENT_CELIST
135 _histogram
[listSize
/ CELIST_BUFFER_SIZE
] += 1;
138 uint32_t *newCEs
= NEW_ARRAY(uint32_t, newMax
);
140 if (newCEs
== NULL
) {
141 status
= U_MEMORY_ALLOCATION_ERROR
;
145 uprv_memcpy(newCEs
, ces
, listSize
* sizeof(uint32_t));
147 if (ces
!= ceBuffer
) {
155 ces
[listSize
++] = ce
;
158 uint32_t CEList::get(int32_t index
) const
160 if (index
>= 0 && index
< listSize
) {
164 return UCOL_NULLORDER
;
167 uint32_t &CEList::operator[](int32_t index
) const
172 UBool
CEList::matchesAt(int32_t offset
, const CEList
*other
) const
174 if (other
== NULL
|| listSize
- offset
< other
->size()) {
178 for (int32_t i
= offset
, j
= 0; j
< other
->size(); i
+= 1, j
+= 1) {
179 if (ces
[i
] != (*other
)[j
]) {
187 int32_t CEList::size() const
192 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(StringList
)
194 #ifdef INSTRUMENT_STRING_LIST
195 int32_t StringList::_lists
= 0;
196 int32_t StringList::_strings
= 0;
197 int32_t StringList::_histogram
[101] = {0};
200 StringList::StringList(UErrorCode
&status
)
201 : strings(NULL
), listMax(STRING_LIST_BUFFER_SIZE
), listSize(0)
203 if (U_FAILURE(status
)) {
207 strings
= new UnicodeString
[listMax
];
209 if (strings
== NULL
) {
210 status
= U_MEMORY_ALLOCATION_ERROR
;
214 #ifdef INSTRUMENT_STRING_LIST
220 StringList::~StringList()
225 void StringList::add(const UnicodeString
*string
, UErrorCode
&status
)
227 if (U_FAILURE(status
)) {
231 #ifdef INSTRUMENT_STRING_LIST
235 if (listSize
>= listMax
) {
236 int32_t newMax
= listMax
+ STRING_LIST_BUFFER_SIZE
;
238 UnicodeString
*newStrings
= new UnicodeString
[newMax
];
240 uprv_memcpy(newStrings
, strings
, listSize
* sizeof(UnicodeString
));
242 #ifdef INSTRUMENT_STRING_LIST
243 int32_t _h
= listSize
/ STRING_LIST_BUFFER_SIZE
;
253 strings
= newStrings
;
257 // The ctor initialized all the strings in
258 // the array to empty strings, so this
259 // is the same as copying the source string.
260 strings
[listSize
++].append(*string
);
263 void StringList::add(const UChar
*chars
, int32_t count
, UErrorCode
&status
)
265 const UnicodeString
string(chars
, count
);
267 add(&string
, status
);
270 const UnicodeString
*StringList::get(int32_t index
) const
272 if (index
>= 0 && index
< listSize
) {
273 return &strings
[index
];
279 int32_t StringList::size() const
285 U_CFUNC
void deleteStringList(void *obj
);
287 class CEToStringsMap
: public UMemory
291 CEToStringsMap(UErrorCode
&status
);
294 void put(uint32_t ce
, UnicodeString
*string
, UErrorCode
&status
);
295 StringList
*getStringList(uint32_t ce
) const;
299 void putStringList(uint32_t ce
, StringList
*stringList
, UErrorCode
&status
);
303 CEToStringsMap::CEToStringsMap(UErrorCode
&status
)
306 if (U_FAILURE(status
)) {
310 map
= uhash_open(uhash_hashLong
, uhash_compareLong
,
311 uhash_compareCaselessUnicodeString
,
314 if (U_FAILURE(status
)) {
318 uhash_setValueDeleter(map
, deleteStringList
);
321 CEToStringsMap::~CEToStringsMap()
326 void CEToStringsMap::put(uint32_t ce
, UnicodeString
*string
, UErrorCode
&status
)
328 StringList
*strings
= getStringList(ce
);
330 if (strings
== NULL
) {
331 strings
= new StringList(status
);
333 if (strings
== NULL
|| U_FAILURE(status
)) {
334 status
= U_MEMORY_ALLOCATION_ERROR
;
338 putStringList(ce
, strings
, status
);
341 strings
->add(string
, status
);
344 StringList
*CEToStringsMap::getStringList(uint32_t ce
) const
346 return (StringList
*) uhash_iget(map
, ce
);
349 void CEToStringsMap::putStringList(uint32_t ce
, StringList
*stringList
, UErrorCode
&status
)
351 uhash_iput(map
, ce
, (void *) stringList
, &status
);
354 U_CFUNC
void deleteStringList(void *obj
)
356 StringList
*strings
= (StringList
*) obj
;
361 U_CFUNC
void deleteCEList(void *obj
);
362 U_CFUNC
void deleteUnicodeStringKey(void *obj
);
364 class StringToCEsMap
: public UMemory
367 StringToCEsMap(UErrorCode
&status
);
370 void put(const UnicodeString
*string
, const CEList
*ces
, UErrorCode
&status
);
371 const CEList
*get(const UnicodeString
*string
);
372 void free(const CEList
*list
);
380 StringToCEsMap::StringToCEsMap(UErrorCode
&status
)
383 if (U_FAILURE(status
)) {
387 map
= uhash_open(uhash_hashUnicodeString
,
388 uhash_compareUnicodeString
,
392 if (U_FAILURE(status
)) {
396 uhash_setValueDeleter(map
, deleteCEList
);
397 uhash_setKeyDeleter(map
, deleteUnicodeStringKey
);
400 StringToCEsMap::~StringToCEsMap()
405 void StringToCEsMap::put(const UnicodeString
*string
, const CEList
*ces
, UErrorCode
&status
)
407 uhash_put(map
, (void *) string
, (void *) ces
, &status
);
410 const CEList
*StringToCEsMap::get(const UnicodeString
*string
)
412 return (const CEList
*) uhash_get(map
, string
);
415 U_CFUNC
void deleteCEList(void *obj
)
417 CEList
*list
= (CEList
*) obj
;
422 U_CFUNC
void deleteUnicodeStringKey(void *obj
)
424 UnicodeString
*key
= (UnicodeString
*) obj
;
429 class CollDataCacheEntry
: public UMemory
432 CollDataCacheEntry(CollData
*theData
);
433 ~CollDataCacheEntry();
439 CollDataCacheEntry::CollDataCacheEntry(CollData
*theData
)
440 : data(theData
), refCount(1)
442 // nothing else to do
445 CollDataCacheEntry::~CollDataCacheEntry()
451 class CollDataCache
: public UMemory
454 CollDataCache(UErrorCode
&status
);
457 CollData
*get(UCollator
*collator
, UErrorCode
&status
);
458 void unref(CollData
*collData
);
463 static char *getKey(UCollator
*collator
, char *keyBuffer
, int32_t *charBufferLength
);
464 static void deleteKey(char *key
);
470 U_CFUNC
void deleteChars(void * /*obj*/)
472 // char *chars = (char *) obj;
473 // All the key strings are owned by the
474 // CollData objects and don't need to
476 //DELETE_ARRAY(chars);
479 U_CFUNC
void deleteCollDataCacheEntry(void *obj
)
481 CollDataCacheEntry
*entry
= (CollDataCacheEntry
*) obj
;
486 CollDataCache::CollDataCache(UErrorCode
&status
)
487 : lock(0), cache(NULL
)
489 if (U_FAILURE(status
)) {
493 cache
= uhash_open(uhash_hashChars
, uhash_compareChars
, uhash_compareLong
, &status
);
495 if (U_FAILURE(status
)) {
499 uhash_setValueDeleter(cache
, deleteCollDataCacheEntry
);
500 uhash_setKeyDeleter(cache
, deleteChars
);
503 CollDataCache::~CollDataCache()
513 CollData
*CollDataCache::get(UCollator
*collator
, UErrorCode
&status
)
515 char keyBuffer
[KEY_BUFFER_SIZE
];
516 int32_t keyLength
= KEY_BUFFER_SIZE
;
517 char *key
= getKey(collator
, keyBuffer
, &keyLength
);
518 CollData
*result
= NULL
, *newData
= NULL
;
519 CollDataCacheEntry
*entry
= NULL
, *newEntry
= NULL
;
522 entry
= (CollDataCacheEntry
*) uhash_get(cache
, key
);
527 newData
= new CollData(collator
, key
, keyLength
, status
);
528 newEntry
= new CollDataCacheEntry(newData
);
530 if (U_FAILURE(status
) || newData
== NULL
|| newEntry
== NULL
) {
531 status
= U_MEMORY_ALLOCATION_ERROR
;
536 entry
= (CollDataCacheEntry
*) uhash_get(cache
, key
);
539 uhash_put(cache
, newData
->key
, newEntry
, &status
);
542 if (U_FAILURE(status
)) {
553 result
= entry
->data
;
554 entry
->refCount
+= 1;
557 if (key
!= keyBuffer
) {
561 if (newEntry
!= NULL
) {
569 void CollDataCache::unref(CollData
*collData
)
571 CollDataCacheEntry
*entry
= NULL
;
574 entry
= (CollDataCacheEntry
*) uhash_get(cache
, collData
->key
);
577 entry
->refCount
-= 1;
582 char *CollDataCache::getKey(UCollator
*collator
, char *keyBuffer
, int32_t *keyBufferLength
)
584 UErrorCode status
= U_ZERO_ERROR
;
585 int32_t len
= ucol_getShortDefinitionString(collator
, NULL
, keyBuffer
, *keyBufferLength
, &status
);
587 if (len
>= *keyBufferLength
) {
588 *keyBufferLength
= (len
+ 2) & ~1; // round to even length, leaving room for terminating null
589 keyBuffer
= NEW_ARRAY(char, *keyBufferLength
);
590 status
= U_ZERO_ERROR
;
592 len
= ucol_getShortDefinitionString(collator
, NULL
, keyBuffer
, *keyBufferLength
, &status
);
595 keyBuffer
[len
] = '\0';
600 void CollDataCache::flush()
602 const UHashElement
*element
;
606 while ((element
= uhash_nextElement(cache
, &pos
)) != NULL
) {
607 CollDataCacheEntry
*entry
= (CollDataCacheEntry
*) element
->value
.pointer
;
609 if (entry
->refCount
<= 0) {
610 uhash_removeElement(cache
, element
);
616 void CollDataCache::deleteKey(char *key
)
622 static UBool
coll_data_cleanup(void) {
623 CollData::freeCollDataCache();
628 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CollData
)
635 #define CLONE_COLLATOR
637 //#define CACHE_CELISTS
638 CollData::CollData(UCollator
*collator
, char *cacheKey
, int32_t cacheKeyLength
, UErrorCode
&status
)
639 : coll(NULL
), charsToCEList(NULL
), ceToCharsStartingWith(NULL
), key(NULL
)
641 // [:c:] == [[:cn:][:cc:][:co:][:cf:][:cs:]]
642 // i.e. other, control, private use, format, surrogate
643 U_STRING_DECL(test_pattern
, "[[:assigned:]-[:c:]]", 20);
644 U_STRING_INIT(test_pattern
, "[[:assigned:]-[:c:]]", 20);
645 USet
*charsToTest
= uset_openPattern(test_pattern
, 20, &status
);
647 // Han ext. A, Han, Jamo, Hangul, Han Ext. B
648 // i.e. all the characers we handle implicitly
649 U_STRING_DECL(remove_pattern
, "[[\\u3400-\\u9FFF][\\u1100-\\u11F9][\\uAC00-\\uD7AF][\\U00020000-\\U0002A6DF]]", 70);
650 U_STRING_INIT(remove_pattern
, "[[\\u3400-\\u9FFF][\\u1100-\\u11F9][\\uAC00-\\uD7AF][\\U00020000-\\U0002A6DF]]", 70);
651 USet
*charsToRemove
= uset_openPattern(remove_pattern
, 70, &status
);
653 if (U_FAILURE(status
)) {
657 USet
*expansions
= uset_openEmpty();
658 USet
*contractions
= uset_openEmpty();
662 charsToCEList
= new StringToCEsMap(status
);
664 if (U_FAILURE(status
)) {
668 charsToCEList
= NULL
;
671 ceToCharsStartingWith
= new CEToStringsMap(status
);
673 if (U_FAILURE(status
)) {
677 if (cacheKeyLength
> KEY_BUFFER_SIZE
) {
678 key
= NEW_ARRAY(char, cacheKeyLength
);
681 status
= U_MEMORY_ALLOCATION_ERROR
;
688 ARRAY_COPY(key
, cacheKey
, cacheKeyLength
);
690 #ifdef CLONE_COLLATOR
691 coll
= ucol_safeClone(collator
, NULL
, NULL
, &status
);
693 if (U_FAILURE(status
)) {
700 ucol_getContractionsAndExpansions(coll
, contractions
, expansions
, FALSE
, &status
);
702 uset_addAll(charsToTest
, contractions
);
703 uset_addAll(charsToTest
, expansions
);
704 uset_removeAll(charsToTest
, charsToRemove
);
706 itemCount
= uset_getItemCount(charsToTest
);
707 for(int32_t item
= 0; item
< itemCount
; item
+= 1) {
708 UChar32 start
= 0, end
= 0;
710 int32_t len
= uset_getItem(charsToTest
, item
, &start
, &end
,
711 buffer
, 16, &status
);
714 for (UChar32 ch
= start
; ch
<= end
; ch
+= 1) {
715 UnicodeString
*st
= new UnicodeString(ch
);
718 status
= U_MEMORY_ALLOCATION_ERROR
;
722 CEList
*ceList
= new CEList(coll
, *st
, status
);
724 ceToCharsStartingWith
->put(ceList
->get(0), st
, status
);
727 charsToCEList
->put(st
, ceList
, status
);
733 } else if (len
> 0) {
734 UnicodeString
*st
= new UnicodeString(buffer
, len
);
737 status
= U_MEMORY_ALLOCATION_ERROR
;
741 CEList
*ceList
= new CEList(coll
, *st
, status
);
743 ceToCharsStartingWith
->put(ceList
->get(0), st
, status
);
746 charsToCEList
->put(st
, ceList
, status
);
752 // shouldn't happen...
755 if (U_FAILURE(status
)) {
761 uset_close(contractions
);
762 uset_close(expansions
);
763 uset_close(charsToRemove
);
764 uset_close(charsToTest
);
766 if (U_FAILURE(status
)) {
770 UChar32 hanRanges
[] = {UCOL_FIRST_HAN
, UCOL_LAST_HAN
, UCOL_FIRST_HAN_COMPAT
, UCOL_LAST_HAN_COMPAT
, UCOL_FIRST_HAN_A
, UCOL_LAST_HAN_A
,
771 UCOL_FIRST_HAN_B
, UCOL_LAST_HAN_B
};
772 UChar jamoRanges
[] = {UCOL_FIRST_L_JAMO
, UCOL_FIRST_V_JAMO
, UCOL_FIRST_T_JAMO
, UCOL_LAST_T_JAMO
};
773 UnicodeString hanString
= UnicodeString::fromUTF32(hanRanges
, ARRAY_SIZE(hanRanges
));
774 UnicodeString
jamoString(FALSE
, jamoRanges
, ARRAY_SIZE(jamoRanges
));
775 CEList
hanList(coll
, hanString
, status
);
776 CEList
jamoList(coll
, jamoString
, status
);
779 if (U_FAILURE(status
)) {
783 for (int32_t c
= 0; c
< jamoList
.size(); c
+= 1) {
784 uint32_t jce
= jamoList
[c
];
786 if (! isContinuation(jce
)) {
787 jamoLimits
[j
++] = jce
;
791 jamoLimits
[3] += (1 << UCOL_PRIMARYORDERSHIFT
);
796 for(int32_t h
= 0; h
< hanList
.size(); h
+= 2) {
797 uint32_t han
= (uint32_t) hanList
[h
];
808 maxHan
+= (1 << UCOL_PRIMARYORDERSHIFT
);
811 CollData::~CollData()
813 #ifdef CLONE_COLLATOR
817 if (key
!= keyBuffer
) {
821 delete ceToCharsStartingWith
;
824 delete charsToCEList
;
828 UCollator
*CollData::getCollator() const
833 const StringList
*CollData::getStringList(int32_t ce
) const
835 return ceToCharsStartingWith
->getStringList(ce
);
838 const CEList
*CollData::getCEList(const UnicodeString
*string
) const
841 return charsToCEList
->get(string
);
843 UErrorCode status
= U_ZERO_ERROR
;
844 const CEList
*list
= new CEList(coll
, *string
, status
);
846 if (U_FAILURE(status
)) {
855 void CollData::freeCEList(const CEList
*list
)
857 #ifndef CACHE_CELISTS
862 int32_t CollData::minLengthInChars(const CEList
*ceList
, int32_t offset
, int32_t *history
) const
864 // find out shortest string for the longest sequence of ces.
865 // this can probably be folded with the minLengthCache...
867 if (history
[offset
] >= 0) {
868 return history
[offset
];
871 uint32_t ce
= ceList
->get(offset
);
872 int32_t maxOffset
= ceList
->size();
873 int32_t shortestLength
= INT32_MAX
;
874 const StringList
*strings
= ceToCharsStartingWith
->getStringList(ce
);
876 if (strings
!= NULL
) {
877 int32_t stringCount
= strings
->size();
879 for (int32_t s
= 0; s
< stringCount
; s
+= 1) {
880 const UnicodeString
*string
= strings
->get(s
);
882 const CEList
*ceList2
= charsToCEList
->get(string
);
884 UErrorCode status
= U_ZERO_ERROR
;
885 const CEList
*ceList2
= new CEList(coll
, *string
, status
);
887 if (U_FAILURE(status
)) {
893 if (ceList
->matchesAt(offset
, ceList2
)) {
894 int32_t clength
= ceList2
->size();
895 int32_t slength
= string
->length();
896 int32_t roffset
= offset
+ clength
;
899 if (roffset
< maxOffset
) {
900 rlength
= minLengthInChars(ceList
, roffset
, history
);
903 // delete before continue to avoid memory leak.
904 #ifndef CACHE_CELISTS
907 // ignore any dead ends
912 if (shortestLength
> slength
+ rlength
) {
913 shortestLength
= slength
+ rlength
;
917 #ifndef CACHE_CELISTS
923 if (shortestLength
== INT32_MAX
) {
924 // No matching strings at this offset. See if
925 // the CE is in a range we can handle manually.
926 if (ce
>= minHan
&& ce
< maxHan
) {
927 // all han have implicit orders which
929 int32_t roffset
= offset
+ 2;
932 //history[roffset++] = -1;
933 //history[roffset++] = 1;
935 if (roffset
< maxOffset
) {
936 rlength
= minLengthInChars(ceList
, roffset
, history
);
943 shortestLength
= 1 + rlength
;
945 } else if (ce
>= jamoLimits
[0] && ce
< jamoLimits
[3]) {
946 int32_t roffset
= offset
;
949 // **** this loop may not handle archaic Hangul correctly ****
950 for (int32_t j
= 0; roffset
< maxOffset
&& j
< 4; j
+= 1, roffset
+= 1) {
951 uint32_t jce
= ceList
->get(roffset
);
953 // Some Jamo have 24-bit primary order; skip the
954 // 2nd CE. This should always be OK because if
955 // we're still in the loop all we've seen are
956 // a series of Jamo in LVT order.
957 if (isContinuation(jce
)) {
961 if (j
>= 3 || jce
< jamoLimits
[j
] || jce
>= jamoLimits
[j
+ 1]) {
966 if (roffset
== offset
) {
967 // we started with a non-L Jamo...
968 // just say it comes from a single character
971 // See if the single Jamo has a 24-bit order.
972 if (roffset
< maxOffset
&& isContinuation(ceList
->get(roffset
))) {
977 if (roffset
< maxOffset
) {
978 rlength
= minLengthInChars(ceList
, roffset
, history
);
985 shortestLength
= 1 + rlength
;
989 // Can't handle it manually either. Just move on.
994 history
[offset
] = shortestLength
;
996 return shortestLength
;
999 int32_t CollData::minLengthInChars(const CEList
*ceList
, int32_t offset
) const
1001 int32_t clength
= ceList
->size();
1002 int32_t *history
= NEW_ARRAY(int32_t, clength
);
1004 for (int32_t i
= 0; i
< clength
; i
+= 1) {
1008 int32_t minLength
= minLengthInChars(ceList
, offset
, history
);
1010 DELETE_ARRAY(history
);
1015 CollData
*CollData::open(UCollator
*collator
, UErrorCode
&status
)
1017 if (U_FAILURE(status
)) {
1021 CollDataCache
*cache
= getCollDataCache();
1023 return cache
->get(collator
, status
);
1026 void CollData::close(CollData
*collData
)
1028 CollDataCache
*cache
= getCollDataCache();
1030 cache
->unref(collData
);
1033 CollDataCache
*CollData::collDataCache
= NULL
;
1035 CollDataCache
*CollData::getCollDataCache()
1037 UErrorCode status
= U_ZERO_ERROR
;
1038 CollDataCache
*cache
= NULL
;
1040 UMTX_CHECK(NULL
, collDataCache
, cache
);
1042 if (cache
== NULL
) {
1043 cache
= new CollDataCache(status
);
1045 if (U_FAILURE(status
)) {
1051 if (collDataCache
== NULL
) {
1052 collDataCache
= cache
;
1054 ucln_i18n_registerCleanup(UCLN_I18N_COLL_DATA
, coll_data_cleanup
);
1058 if (collDataCache
!= cache
) {
1063 return collDataCache
;
1066 void CollData::freeCollDataCache()
1068 CollDataCache
*cache
= NULL
;
1070 UMTX_CHECK(NULL
, collDataCache
, cache
);
1072 if (cache
!= NULL
) {
1074 if (collDataCache
!= NULL
) {
1075 collDataCache
= NULL
;
1085 void CollData::flushCollDataCache()
1087 CollDataCache
*cache
= NULL
;
1089 UMTX_CHECK(NULL
, collDataCache
, cache
);
1091 // **** this will fail if the another ****
1092 // **** thread deletes the cache here ****
1093 if (cache
!= NULL
) {
1100 #endif // #if !UCONFIG_NO_COLLATION