ICU-6076 Make it a little easier to detect initialization problems, and
improve initialization time. X-SVN-Rev: 23442
This commit is contained in:
parent
6feced2f5d
commit
8c56e56382
@ -1503,6 +1503,8 @@ private:
|
||||
UnicodeString& rebuiltPat,
|
||||
UErrorCode& ec);
|
||||
|
||||
static const UnicodeSet* getInclusions(int32_t src, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* A filter that returns TRUE if the given code point should be
|
||||
* included in the UnicodeSet being constructed.
|
||||
|
@ -1446,8 +1446,14 @@ UnicodeSet& UnicodeSet::compact() {
|
||||
if (len < capacity) {
|
||||
// Make the capacity equal to len or 1.
|
||||
// We don't want to realloc of 0 size.
|
||||
capacity = len + (len == 0);
|
||||
list = (UChar32*) uprv_realloc(list, sizeof(UChar32) * capacity);
|
||||
int32_t newCapacity = len + (len == 0);
|
||||
UChar32* temp = (UChar32*) uprv_realloc(list, sizeof(UChar32) * newCapacity);
|
||||
if (temp) {
|
||||
list = temp;
|
||||
capacity = newCapacity;
|
||||
}
|
||||
// else what the heck happened?! We allocated less memory!
|
||||
// Oh well. We'll keep our original array.
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
@ -136,7 +136,14 @@ U_CDECL_END
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
static const UnicodeSet* getInclusions(int32_t src, UErrorCode &status) {
|
||||
/*
|
||||
Reduce excessive reallocation, and make it easier to detect initialization
|
||||
problems.
|
||||
Usually you don't see smaller sets than this for Unicode 5.0.
|
||||
*/
|
||||
#define DEFAULT_INCLUSION_CAPACITY 3072
|
||||
|
||||
const UnicodeSet* UnicodeSet::getInclusions(int32_t src, UErrorCode &status) {
|
||||
UBool needInit;
|
||||
UMTX_CHECK(NULL, (INCLUSIONS[src] == NULL), needInit);
|
||||
if (needInit) {
|
||||
@ -146,9 +153,10 @@ static const UnicodeSet* getInclusions(int32_t src, UErrorCode &status) {
|
||||
_set_add,
|
||||
_set_addRange,
|
||||
_set_addString,
|
||||
NULL // don't need remove()
|
||||
NULL, // don't need remove()
|
||||
NULL // don't need removeRange()
|
||||
};
|
||||
|
||||
incl->ensureCapacity(DEFAULT_INCLUSION_CAPACITY, status);
|
||||
if (incl != NULL) {
|
||||
switch(src) {
|
||||
case UPROPS_SRC_CHAR:
|
||||
@ -894,7 +902,7 @@ void UnicodeSet::applyFilter(UnicodeSet::Filter filter,
|
||||
clear();
|
||||
|
||||
UChar32 startHasProperty = -1;
|
||||
int limitRange = inclusions->getRangeCount();
|
||||
int32_t limitRange = inclusions->getRangeCount();
|
||||
|
||||
for (int j=0; j<limitRange; ++j) {
|
||||
// get current range
|
||||
@ -1322,7 +1330,8 @@ UnicodeSet& UnicodeSet::closeOver(int32_t attribute) {
|
||||
_set_add,
|
||||
_set_addRange,
|
||||
_set_addString,
|
||||
NULL // don't need remove()
|
||||
NULL, // don't need remove()
|
||||
NULL // don't need removeRange()
|
||||
};
|
||||
|
||||
// start with input set to guarantee inclusion
|
||||
|
Loading…
Reference in New Issue
Block a user