diff options
author | mcheshkov <mcheshkov@yandex-team.ru> | 2022-02-10 16:46:16 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:16 +0300 |
commit | 1312621288956f199a5bd5342b0133d4395fa725 (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /contrib/libs/icu/common/uniset.cpp | |
parent | e9d19cec64684c9c1e6b0c98297e5b895cf904fe (diff) | |
download | ydb-1312621288956f199a5bd5342b0133d4395fa725.tar.gz |
Restoring authorship annotation for <mcheshkov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/icu/common/uniset.cpp')
-rw-r--r-- | contrib/libs/icu/common/uniset.cpp | 508 |
1 files changed, 254 insertions, 254 deletions
diff --git a/contrib/libs/icu/common/uniset.cpp b/contrib/libs/icu/common/uniset.cpp index c0021fd0b1..b73d612f24 100644 --- a/contrib/libs/icu/common/uniset.cpp +++ b/contrib/libs/icu/common/uniset.cpp @@ -1,4 +1,4 @@ -// © 2016 and later: Unicode, Inc. and others. +// © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /* ********************************************************************** @@ -14,7 +14,7 @@ #include "unicode/parsepos.h" #include "unicode/symtable.h" #include "unicode/uniset.h" -#include "unicode/ustring.h" +#include "unicode/ustring.h" #include "unicode/utf8.h" #include "unicode/utf16.h" #include "ruleiter.h" @@ -54,8 +54,8 @@ // LOW <= all valid values. ZERO for codepoints #define UNICODESET_LOW 0x000000 -/** Max list [0, 1, 2, ..., max code point, HIGH] */ -constexpr int32_t MAX_LENGTH = UNICODESET_HIGH + 1; +/** Max list [0, 1, 2, ..., max code point, HIGH] */ +constexpr int32_t MAX_LENGTH = UNICODESET_HIGH + 1; U_NAMESPACE_BEGIN @@ -135,18 +135,18 @@ static int8_t U_CALLCONV compareUnicodeString(UElement t1, UElement t2) { return a.compare(b); } -UBool UnicodeSet::hasStrings() const { - return strings != nullptr && !strings->isEmpty(); -} - -int32_t UnicodeSet::stringsSize() const { - return strings == nullptr ? 0 : strings->size(); -} - -UBool UnicodeSet::stringsContains(const UnicodeString &s) const { - return strings != nullptr && strings->contains((void*) &s); -} - +UBool UnicodeSet::hasStrings() const { + return strings != nullptr && !strings->isEmpty(); +} + +int32_t UnicodeSet::stringsSize() const { + return strings == nullptr ? 0 : strings->size(); +} + +UBool UnicodeSet::stringsContains(const UnicodeString &s) const { + return strings != nullptr && strings->contains((void*) &s); +} + //---------------------------------------------------------------- // Constructors &c //---------------------------------------------------------------- @@ -154,8 +154,8 @@ UBool UnicodeSet::stringsContains(const UnicodeString &s) const { /** * Constructs an empty set. */ -UnicodeSet::UnicodeSet() { - list[0] = UNICODESET_HIGH; +UnicodeSet::UnicodeSet() { + list[0] = UNICODESET_HIGH; _dbgct(this); } @@ -166,38 +166,38 @@ UnicodeSet::UnicodeSet() { * @param start first character, inclusive, of range * @param end last character, inclusive, of range */ -UnicodeSet::UnicodeSet(UChar32 start, UChar32 end) { - list[0] = UNICODESET_HIGH; - add(start, end); +UnicodeSet::UnicodeSet(UChar32 start, UChar32 end) { + list[0] = UNICODESET_HIGH; + add(start, end); _dbgct(this); } /** * Constructs a set that is identical to the given UnicodeSet. */ -UnicodeSet::UnicodeSet(const UnicodeSet& o) : UnicodeFilter(o) { - *this = o; +UnicodeSet::UnicodeSet(const UnicodeSet& o) : UnicodeFilter(o) { + *this = o; _dbgct(this); } // Copy-construct as thawed. -UnicodeSet::UnicodeSet(const UnicodeSet& o, UBool /* asThawed */) : UnicodeFilter(o) { - if (ensureCapacity(o.len)) { +UnicodeSet::UnicodeSet(const UnicodeSet& o, UBool /* asThawed */) : UnicodeFilter(o) { + if (ensureCapacity(o.len)) { // *this = o except for bmpSet and stringSpan len = o.len; uprv_memcpy(list, o.list, (size_t)len*sizeof(UChar32)); - if (o.hasStrings()) { - UErrorCode status = U_ZERO_ERROR; - if (!allocateStrings(status) || - (strings->assign(*o.strings, cloneUnicodeString, status), U_FAILURE(status))) { - setToBogus(); - return; - } + if (o.hasStrings()) { + UErrorCode status = U_ZERO_ERROR; + if (!allocateStrings(status) || + (strings->assign(*o.strings, cloneUnicodeString, status), U_FAILURE(status))) { + setToBogus(); + return; + } } if (o.pat) { - setPattern(o.pat, o.patLen); + setPattern(o.pat, o.patLen); } - _dbgct(this); + _dbgct(this); } } @@ -206,11 +206,11 @@ UnicodeSet::UnicodeSet(const UnicodeSet& o, UBool /* asThawed */) : UnicodeFilte */ UnicodeSet::~UnicodeSet() { _dbgdt(this); // first! - if (list != stackList) { - uprv_free(list); - } + if (list != stackList) { + uprv_free(list); + } delete bmpSet; - if (buffer != stackList) { + if (buffer != stackList) { uprv_free(buffer); } delete strings; @@ -222,10 +222,10 @@ UnicodeSet::~UnicodeSet() { * Assigns this object to be a copy of another. */ UnicodeSet& UnicodeSet::operator=(const UnicodeSet& o) { - return copyFrom(o, FALSE); -} - -UnicodeSet& UnicodeSet::copyFrom(const UnicodeSet& o, UBool asThawed) { + return copyFrom(o, FALSE); +} + +UnicodeSet& UnicodeSet::copyFrom(const UnicodeSet& o, UBool asThawed) { if (this == &o) { return *this; } @@ -236,30 +236,30 @@ UnicodeSet& UnicodeSet::copyFrom(const UnicodeSet& o, UBool asThawed) { setToBogus(); return *this; } - if (!ensureCapacity(o.len)) { - // ensureCapacity will mark the UnicodeSet as Bogus if OOM failure happens. - return *this; + if (!ensureCapacity(o.len)) { + // ensureCapacity will mark the UnicodeSet as Bogus if OOM failure happens. + return *this; } len = o.len; uprv_memcpy(list, o.list, (size_t)len*sizeof(UChar32)); - if (o.bmpSet != nullptr && !asThawed) { + if (o.bmpSet != nullptr && !asThawed) { bmpSet = new BMPSet(*o.bmpSet, list, len); if (bmpSet == NULL) { // Check for memory allocation error. setToBogus(); return *this; } } - if (o.hasStrings()) { - UErrorCode status = U_ZERO_ERROR; - if ((strings == nullptr && !allocateStrings(status)) || - (strings->assign(*o.strings, cloneUnicodeString, status), U_FAILURE(status))) { - setToBogus(); - return *this; - } - } else if (hasStrings()) { - strings->removeAllElements(); - } - if (o.stringSpan != nullptr && !asThawed) { + if (o.hasStrings()) { + UErrorCode status = U_ZERO_ERROR; + if ((strings == nullptr && !allocateStrings(status)) || + (strings->assign(*o.strings, cloneUnicodeString, status), U_FAILURE(status))) { + setToBogus(); + return *this; + } + } else if (hasStrings()) { + strings->removeAllElements(); + } + if (o.stringSpan != nullptr && !asThawed) { stringSpan = new UnicodeSetStringSpan(*o.stringSpan, *strings); if (stringSpan == NULL) { // Check for memory allocation error. setToBogus(); @@ -268,7 +268,7 @@ UnicodeSet& UnicodeSet::copyFrom(const UnicodeSet& o, UBool asThawed) { } releasePattern(); if (o.pat) { - setPattern(o.pat, o.patLen); + setPattern(o.pat, o.patLen); } return *this; } @@ -278,11 +278,11 @@ UnicodeSet& UnicodeSet::copyFrom(const UnicodeSet& o, UBool asThawed) { * to support cloning in order to allow classes using * UnicodeMatchers, such as Transliterator, to implement cloning. */ -UnicodeSet* UnicodeSet::clone() const { +UnicodeSet* UnicodeSet::clone() const { return new UnicodeSet(*this); } -UnicodeSet *UnicodeSet::cloneAsThawed() const { +UnicodeSet *UnicodeSet::cloneAsThawed() const { return new UnicodeSet(*this, TRUE); } @@ -301,8 +301,8 @@ UBool UnicodeSet::operator==(const UnicodeSet& o) const { for (int32_t i = 0; i < len; ++i) { if (list[i] != o.list[i]) return FALSE; } - if (hasStrings() != o.hasStrings()) { return FALSE; } - if (hasStrings() && *strings != *o.strings) return FALSE; + if (hasStrings() != o.hasStrings()) { return FALSE; } + if (hasStrings() && *strings != *o.strings) return FALSE; return TRUE; } @@ -313,12 +313,12 @@ UBool UnicodeSet::operator==(const UnicodeSet& o) const { * @see Object#hashCode() */ int32_t UnicodeSet::hashCode(void) const { - uint32_t result = static_cast<uint32_t>(len); + uint32_t result = static_cast<uint32_t>(len); for (int32_t i = 0; i < len; ++i) { - result *= 1000003u; + result *= 1000003u; result += list[i]; } - return static_cast<int32_t>(result); + return static_cast<int32_t>(result); } //---------------------------------------------------------------- @@ -338,7 +338,7 @@ int32_t UnicodeSet::size(void) const { for (int32_t i = 0; i < count; ++i) { n += getRangeEnd(i) - getRangeStart(i) + 1; } - return n + stringsSize(); + return n + stringsSize(); } /** @@ -347,7 +347,7 @@ int32_t UnicodeSet::size(void) const { * @return <tt>true</tt> if this set contains no elements. */ UBool UnicodeSet::isEmpty(void) const { - return len == 1 && !hasStrings(); + return len == 1 && !hasStrings(); } /** @@ -447,7 +447,7 @@ UBool UnicodeSet::contains(const UnicodeString& s) const { if (s.length() == 0) return FALSE; int32_t cp = getSingleCP(s); if (cp < 0) { - return stringsContains(s); + return stringsContains(s); } else { return contains((UChar32) cp); } @@ -469,7 +469,7 @@ UBool UnicodeSet::containsAll(const UnicodeSet& c) const { return FALSE; } } - return !c.hasStrings() || (strings != nullptr && strings->containsAll(*c.strings)); + return !c.hasStrings() || (strings != nullptr && strings->containsAll(*c.strings)); } /** @@ -515,7 +515,7 @@ UBool UnicodeSet::containsNone(const UnicodeSet& c) const { return FALSE; } } - return strings == nullptr || !c.hasStrings() || strings->containsNone(*c.strings); + return strings == nullptr || !c.hasStrings() || strings->containsNone(*c.strings); } /** @@ -556,7 +556,7 @@ UBool UnicodeSet::matchesIndexValue(uint8_t v) const { return TRUE; } } - if (hasStrings()) { + if (hasStrings()) { for (i=0; i<strings->size(); ++i) { const UnicodeString& s = *(const UnicodeString*)strings->elementAt(i); //if (s.length() == 0) { @@ -591,7 +591,7 @@ UMatchDegree UnicodeSet::matches(const Replaceable& text, return U_MISMATCH; } } else { - if (hasStrings()) { // try strings first + if (hasStrings()) { // try strings first // might separate forward and backward loops later // for now they are combined @@ -792,39 +792,39 @@ UnicodeSet& UnicodeSet::set(UChar32 start, UChar32 end) { */ UnicodeSet& UnicodeSet::add(UChar32 start, UChar32 end) { if (pinCodePoint(start) < pinCodePoint(end)) { - UChar32 limit = end + 1; - // Fast path for adding a new range after the last one. - // Odd list length: [..., lastStart, lastLimit, HIGH] - if ((len & 1) != 0) { - // If the list is empty, set lastLimit low enough to not be adjacent to 0. - UChar32 lastLimit = len == 1 ? -2 : list[len - 2]; - if (lastLimit <= start && !isFrozen() && !isBogus()) { - if (lastLimit == start) { - // Extend the last range. - list[len - 2] = limit; - if (limit == UNICODESET_HIGH) { - --len; - } - } else { - list[len - 1] = start; - if (limit < UNICODESET_HIGH) { - if (ensureCapacity(len + 2)) { - list[len++] = limit; - list[len++] = UNICODESET_HIGH; - } - } else { // limit == UNICODESET_HIGH - if (ensureCapacity(len + 1)) { - list[len++] = UNICODESET_HIGH; - } - } - } - releasePattern(); - return *this; - } - } - // This is slow. Could be much faster using findCodePoint(start) - // and modifying the list, dealing with adjacent & overlapping ranges. - UChar32 range[3] = { start, limit, UNICODESET_HIGH }; + UChar32 limit = end + 1; + // Fast path for adding a new range after the last one. + // Odd list length: [..., lastStart, lastLimit, HIGH] + if ((len & 1) != 0) { + // If the list is empty, set lastLimit low enough to not be adjacent to 0. + UChar32 lastLimit = len == 1 ? -2 : list[len - 2]; + if (lastLimit <= start && !isFrozen() && !isBogus()) { + if (lastLimit == start) { + // Extend the last range. + list[len - 2] = limit; + if (limit == UNICODESET_HIGH) { + --len; + } + } else { + list[len - 1] = start; + if (limit < UNICODESET_HIGH) { + if (ensureCapacity(len + 2)) { + list[len++] = limit; + list[len++] = UNICODESET_HIGH; + } + } else { // limit == UNICODESET_HIGH + if (ensureCapacity(len + 1)) { + list[len++] = UNICODESET_HIGH; + } + } + } + releasePattern(); + return *this; + } + } + // This is slow. Could be much faster using findCodePoint(start) + // and modifying the list, dealing with adjacent & overlapping ranges. + UChar32 range[3] = { start, limit, UNICODESET_HIGH }; add(range, 2, 0); } else if (start == end) { add(start); @@ -893,9 +893,9 @@ UnicodeSet& UnicodeSet::add(UChar32 c) { list[i] = c; // if we touched the HIGH mark, then add a new one if (c == (UNICODESET_HIGH - 1)) { - if (!ensureCapacity(len+1)) { - // ensureCapacity will mark the object as Bogus if OOM failure happens. - return *this; + if (!ensureCapacity(len+1)) { + // ensureCapacity will mark the object as Bogus if OOM failure happens. + return *this; } list[len++] = UNICODESET_HIGH; } @@ -937,13 +937,13 @@ UnicodeSet& UnicodeSet::add(UChar32 c) { // ^ // list[i] - if (!ensureCapacity(len+2)) { - // ensureCapacity will mark the object as Bogus if OOM failure happens. - return *this; + if (!ensureCapacity(len+2)) { + // ensureCapacity will mark the object as Bogus if OOM failure happens. + return *this; } - UChar32 *p = list + i; - uprv_memmove(p + 2, p, (len - i) * sizeof(*p)); + UChar32 *p = list + i; + uprv_memmove(p + 2, p, (len - i) * sizeof(*p)); list[i] = c; list[i+1] = c+1; len += 2; @@ -979,7 +979,7 @@ UnicodeSet& UnicodeSet::add(const UnicodeString& s) { if (s.length() == 0 || isFrozen() || isBogus()) return *this; int32_t cp = getSingleCP(s); if (cp < 0) { - if (!stringsContains(s)) { + if (!stringsContains(s)) { _add(s); releasePattern(); } @@ -998,11 +998,11 @@ void UnicodeSet::_add(const UnicodeString& s) { if (isFrozen() || isBogus()) { return; } - UErrorCode ec = U_ZERO_ERROR; - if (strings == nullptr && !allocateStrings(ec)) { - setToBogus(); - return; - } + UErrorCode ec = U_ZERO_ERROR; + if (strings == nullptr && !allocateStrings(ec)) { + setToBogus(); + return; + } UnicodeString* t = new UnicodeString(s); if (t == NULL) { // Check for memory allocation error. setToBogus(); @@ -1090,10 +1090,10 @@ UnicodeSet& UnicodeSet::removeAll(const UnicodeString& s) { } UnicodeSet& UnicodeSet::removeAllStrings() { - if (!isFrozen() && hasStrings()) { - strings->removeAllElements(); - releasePattern(); - } + if (!isFrozen() && hasStrings()) { + strings->removeAllElements(); + releasePattern(); + } return *this; } @@ -1189,9 +1189,9 @@ UnicodeSet& UnicodeSet::remove(const UnicodeString& s) { if (s.length() == 0 || isFrozen() || isBogus()) return *this; int32_t cp = getSingleCP(s); if (cp < 0) { - if (strings != nullptr && strings->removeElement((void*) &s)) { - releasePattern(); - } + if (strings != nullptr && strings->removeElement((void*) &s)) { + releasePattern(); + } } else { remove((UChar32)cp, (UChar32)cp); } @@ -1234,14 +1234,14 @@ UnicodeSet& UnicodeSet::complement(void) { return *this; } if (list[0] == UNICODESET_LOW) { - uprv_memmove(list, list + 1, (size_t)(len-1)*sizeof(UChar32)); + uprv_memmove(list, list + 1, (size_t)(len-1)*sizeof(UChar32)); --len; } else { - if (!ensureCapacity(len+1)) { + if (!ensureCapacity(len+1)) { return *this; } - uprv_memmove(list + 1, list, (size_t)len*sizeof(UChar32)); - list[0] = UNICODESET_LOW; + uprv_memmove(list + 1, list, (size_t)len*sizeof(UChar32)); + list[0] = UNICODESET_LOW; ++len; } releasePattern(); @@ -1260,7 +1260,7 @@ UnicodeSet& UnicodeSet::complement(const UnicodeString& s) { if (s.length() == 0 || isFrozen() || isBogus()) return *this; int32_t cp = getSingleCP(s); if (cp < 0) { - if (stringsContains(s)) { + if (stringsContains(s)) { strings->removeElement((void*) &s); } else { _add(s); @@ -1291,7 +1291,7 @@ UnicodeSet& UnicodeSet::addAll(const UnicodeSet& c) { if ( c.strings!=NULL ) { for (int32_t i=0; i<c.strings->size(); ++i) { const UnicodeString* s = (const UnicodeString*)c.strings->elementAt(i); - if (!stringsContains(*s)) { + if (!stringsContains(*s)) { _add(*s); } } @@ -1313,13 +1313,13 @@ UnicodeSet& UnicodeSet::retainAll(const UnicodeSet& c) { return *this; } retain(c.list, c.len, 0); - if (hasStrings()) { - if (!c.hasStrings()) { - strings->removeAllElements(); - } else { - strings->retainAll(*c.strings); - } - } + if (hasStrings()) { + if (!c.hasStrings()) { + strings->removeAllElements(); + } else { + strings->retainAll(*c.strings); + } + } return *this; } @@ -1337,9 +1337,9 @@ UnicodeSet& UnicodeSet::removeAll(const UnicodeSet& c) { return *this; } retain(c.list, c.len, 2); - if (hasStrings() && c.hasStrings()) { - strings->removeAll(*c.strings); - } + if (hasStrings() && c.hasStrings()) { + strings->removeAll(*c.strings); + } return *this; } @@ -1357,12 +1357,12 @@ UnicodeSet& UnicodeSet::complementAll(const UnicodeSet& c) { } exclusiveOr(c.list, c.len, 0); - if (c.strings != nullptr) { - for (int32_t i=0; i<c.strings->size(); ++i) { - void* e = c.strings->elementAt(i); - if (strings == nullptr || !strings->removeElement(e)) { - _add(*(const UnicodeString*)e); - } + if (c.strings != nullptr) { + for (int32_t i=0; i<c.strings->size(); ++i) { + void* e = c.strings->elementAt(i); + if (strings == nullptr || !strings->removeElement(e)) { + _add(*(const UnicodeString*)e); + } } } return *this; @@ -1376,14 +1376,14 @@ UnicodeSet& UnicodeSet::clear(void) { if (isFrozen()) { return *this; } - list[0] = UNICODESET_HIGH; + list[0] = UNICODESET_HIGH; len = 1; releasePattern(); if (strings != NULL) { strings->removeAllElements(); } - // Remove bogus - fFlags = 0; + // Remove bogus + fFlags = 0; return *this; } @@ -1430,32 +1430,32 @@ UnicodeSet& UnicodeSet::compact() { return *this; } // Delete buffer first to defragment memory less. - if (buffer != stackList) { + if (buffer != stackList) { uprv_free(buffer); buffer = NULL; - bufferCapacity = 0; - } - if (list == stackList) { - // pass - } else if (len <= INITIAL_CAPACITY) { - uprv_memcpy(stackList, list, len * sizeof(UChar32)); - uprv_free(list); - list = stackList; - capacity = INITIAL_CAPACITY; - } else if ((len + 7) < capacity) { - // If we have more than a little unused capacity, shrink it to len. - UChar32* temp = (UChar32*) uprv_realloc(list, sizeof(UChar32) * len); + bufferCapacity = 0; + } + if (list == stackList) { + // pass + } else if (len <= INITIAL_CAPACITY) { + uprv_memcpy(stackList, list, len * sizeof(UChar32)); + uprv_free(list); + list = stackList; + capacity = INITIAL_CAPACITY; + } else if ((len + 7) < capacity) { + // If we have more than a little unused capacity, shrink it to len. + UChar32* temp = (UChar32*) uprv_realloc(list, sizeof(UChar32) * len); if (temp) { list = temp; - capacity = len; + capacity = len; } // else what the heck happened?! We allocated less memory! // Oh well. We'll keep our original array. } - if (strings != nullptr && strings->isEmpty()) { - delete strings; - strings = nullptr; - } + if (strings != nullptr && strings->isEmpty()) { + delete strings; + strings = nullptr; + } return *this; } @@ -1466,8 +1466,8 @@ UnicodeSet& UnicodeSet::compact() { /** * Deserialize constructor. */ -UnicodeSet::UnicodeSet(const uint16_t data[], int32_t dataLen, ESerialization serialization, - UErrorCode &ec) { +UnicodeSet::UnicodeSet(const uint16_t data[], int32_t dataLen, ESerialization serialization, + UErrorCode &ec) { if(U_FAILURE(ec)) { setToBogus(); @@ -1486,11 +1486,11 @@ UnicodeSet::UnicodeSet(const uint16_t data[], int32_t dataLen, ESerialization se int32_t headerSize = ((data[0]&0x8000)) ?2:1; int32_t bmpLength = (headerSize==1)?data[0]:data[1]; - int32_t newLength = (((data[0]&0x7FFF)-bmpLength)/2)+bmpLength; + int32_t newLength = (((data[0]&0x7FFF)-bmpLength)/2)+bmpLength; #ifdef DEBUG_SERIALIZE - printf("dataLen %d headerSize %d bmpLen %d len %d. data[0]=%X/%X/%X/%X\n", dataLen,headerSize,bmpLength,newLength, data[0],data[1],data[2],data[3]); + printf("dataLen %d headerSize %d bmpLen %d len %d. data[0]=%X/%X/%X/%X\n", dataLen,headerSize,bmpLength,newLength, data[0],data[1],data[2],data[3]); #endif - if(!ensureCapacity(newLength + 1)) { // +1 for HIGH + if(!ensureCapacity(newLength + 1)) { // +1 for HIGH return; } // copy bmp @@ -1502,18 +1502,18 @@ UnicodeSet::UnicodeSet(const uint16_t data[], int32_t dataLen, ESerialization se #endif } // copy smp - for(i=bmpLength;i<newLength;i++) { + for(i=bmpLength;i<newLength;i++) { list[i] = ((UChar32)data[headerSize+bmpLength+(i-bmpLength)*2+0] << 16) + ((UChar32)data[headerSize+bmpLength+(i-bmpLength)*2+1]); #ifdef DEBUG_SERIALIZE printf("<<32@%d+[%d] %lX\n", headerSize+bmpLength+i, i, list[i]); #endif } - U_ASSERT(i == newLength); - if (i == 0 || list[i - 1] != UNICODESET_HIGH) { - list[i++] = UNICODESET_HIGH; - } - len = i; + U_ASSERT(i == newLength); + if (i == 0 || list[i - 1] != UNICODESET_HIGH) { + list[i++] = UNICODESET_HIGH; + } + len = i; } @@ -1634,65 +1634,65 @@ UBool UnicodeSet::allocateStrings(UErrorCode &status) { return TRUE; } -int32_t UnicodeSet::nextCapacity(int32_t minCapacity) { - // Grow exponentially to reduce the frequency of allocations. - if (minCapacity < INITIAL_CAPACITY) { - return minCapacity + INITIAL_CAPACITY; - } else if (minCapacity <= 2500) { - return 5 * minCapacity; - } else { - int32_t newCapacity = 2 * minCapacity; - if (newCapacity > MAX_LENGTH) { - newCapacity = MAX_LENGTH; - } - return newCapacity; - } -} - -bool UnicodeSet::ensureCapacity(int32_t newLen) { - if (newLen > MAX_LENGTH) { - newLen = MAX_LENGTH; - } - if (newLen <= capacity) { - return true; - } - int32_t newCapacity = nextCapacity(newLen); - UChar32* temp = (UChar32*) uprv_malloc(newCapacity * sizeof(UChar32)); +int32_t UnicodeSet::nextCapacity(int32_t minCapacity) { + // Grow exponentially to reduce the frequency of allocations. + if (minCapacity < INITIAL_CAPACITY) { + return minCapacity + INITIAL_CAPACITY; + } else if (minCapacity <= 2500) { + return 5 * minCapacity; + } else { + int32_t newCapacity = 2 * minCapacity; + if (newCapacity > MAX_LENGTH) { + newCapacity = MAX_LENGTH; + } + return newCapacity; + } +} + +bool UnicodeSet::ensureCapacity(int32_t newLen) { + if (newLen > MAX_LENGTH) { + newLen = MAX_LENGTH; + } + if (newLen <= capacity) { + return true; + } + int32_t newCapacity = nextCapacity(newLen); + UChar32* temp = (UChar32*) uprv_malloc(newCapacity * sizeof(UChar32)); if (temp == NULL) { - setToBogus(); // set the object to bogus state if an OOM failure occurred. - return false; + setToBogus(); // set the object to bogus state if an OOM failure occurred. + return false; + } + // Copy only the actual contents. + uprv_memcpy(temp, list, len * sizeof(UChar32)); + if (list != stackList) { + uprv_free(list); } - // Copy only the actual contents. - uprv_memcpy(temp, list, len * sizeof(UChar32)); - if (list != stackList) { - uprv_free(list); - } list = temp; - capacity = newCapacity; - return true; + capacity = newCapacity; + return true; } -bool UnicodeSet::ensureBufferCapacity(int32_t newLen) { - if (newLen > MAX_LENGTH) { - newLen = MAX_LENGTH; - } - if (newLen <= bufferCapacity) { - return true; - } - int32_t newCapacity = nextCapacity(newLen); - UChar32* temp = (UChar32*) uprv_malloc(newCapacity * sizeof(UChar32)); +bool UnicodeSet::ensureBufferCapacity(int32_t newLen) { + if (newLen > MAX_LENGTH) { + newLen = MAX_LENGTH; + } + if (newLen <= bufferCapacity) { + return true; + } + int32_t newCapacity = nextCapacity(newLen); + UChar32* temp = (UChar32*) uprv_malloc(newCapacity * sizeof(UChar32)); if (temp == NULL) { setToBogus(); - return false; + return false; + } + // The buffer has no contents to be copied. + // It is always filled from scratch after this call. + if (buffer != stackList) { + uprv_free(buffer); } - // The buffer has no contents to be copied. - // It is always filled from scratch after this call. - if (buffer != stackList) { - uprv_free(buffer); - } buffer = temp; - bufferCapacity = newCapacity; - return true; + bufferCapacity = newCapacity; + return true; } /** @@ -1729,7 +1729,7 @@ void UnicodeSet::exclusiveOr(const UChar32* other, int32_t otherLen, int8_t pola if (isFrozen() || isBogus()) { return; } - if (!ensureBufferCapacity(len + otherLen)) { + if (!ensureBufferCapacity(len + otherLen)) { return; } @@ -1777,7 +1777,7 @@ void UnicodeSet::add(const UChar32* other, int32_t otherLen, int8_t polarity) { if (isFrozen() || isBogus() || other==NULL) { return; } - if (!ensureBufferCapacity(len + otherLen)) { + if (!ensureBufferCapacity(len + otherLen)) { return; } @@ -1888,7 +1888,7 @@ void UnicodeSet::retain(const UChar32* other, int32_t otherLen, int8_t polarity) if (isFrozen() || isBogus()) { return; } - if (!ensureBufferCapacity(len + otherLen)) { + if (!ensureBufferCapacity(len + otherLen)) { return; } @@ -2134,14 +2134,14 @@ UnicodeString& UnicodeSet::_generatePattern(UnicodeString& result, } } - if (strings != nullptr) { - for (int32_t i = 0; i<strings->size(); ++i) { - result.append(OPEN_BRACE); - _appendToPat(result, - *(const UnicodeString*) strings->elementAt(i), - escapeUnprintable); - result.append(CLOSE_BRACE); - } + if (strings != nullptr) { + for (int32_t i = 0; i<strings->size(); ++i) { + result.append(OPEN_BRACE); + _appendToPat(result, + *(const UnicodeString*) strings->elementAt(i), + escapeUnprintable); + result.append(CLOSE_BRACE); + } } return result.append(SET_CLOSE); } @@ -2160,29 +2160,29 @@ void UnicodeSet::releasePattern() { /** * Set the new pattern to cache. */ -void UnicodeSet::setPattern(const char16_t *newPat, int32_t newPatLen) { +void UnicodeSet::setPattern(const char16_t *newPat, int32_t newPatLen) { releasePattern(); pat = (UChar *)uprv_malloc((newPatLen + 1) * sizeof(UChar)); if (pat) { patLen = newPatLen; - u_memcpy(pat, newPat, patLen); + u_memcpy(pat, newPat, patLen); pat[patLen] = 0; } // else we don't care if malloc failed. This was just a nice cache. // We can regenerate an equivalent pattern later when requested. } -UnicodeSet *UnicodeSet::freeze() { +UnicodeSet *UnicodeSet::freeze() { if(!isFrozen() && !isBogus()) { - compact(); + compact(); - // Optimize contains() and span() and similar functions. - if (hasStrings()) { - stringSpan = new UnicodeSetStringSpan(*this, *strings, UnicodeSetStringSpan::ALL); - if (stringSpan == nullptr) { + // Optimize contains() and span() and similar functions. + if (hasStrings()) { + stringSpan = new UnicodeSetStringSpan(*this, *strings, UnicodeSetStringSpan::ALL); + if (stringSpan == nullptr) { setToBogus(); return this; - } else if (!stringSpan->needsStringSpanUTF16()) { + } else if (!stringSpan->needsStringSpanUTF16()) { // All strings are irrelevant for span() etc. because // all of each string's code points are contained in this set. // Do not check needsStringSpanUTF8() because UTF-8 has at most as @@ -2215,7 +2215,7 @@ int32_t UnicodeSet::span(const UChar *s, int32_t length, USetSpanCondition spanC } if(stringSpan!=NULL) { return stringSpan->span(s, length, spanCondition); - } else if(hasStrings()) { + } else if(hasStrings()) { uint32_t which= spanCondition==USET_SPAN_NOT_CONTAINED ? UnicodeSetStringSpan::FWD_UTF16_NOT_CONTAINED : UnicodeSetStringSpan::FWD_UTF16_CONTAINED; @@ -2252,7 +2252,7 @@ int32_t UnicodeSet::spanBack(const UChar *s, int32_t length, USetSpanCondition s } if(stringSpan!=NULL) { return stringSpan->spanBack(s, length, spanCondition); - } else if(hasStrings()) { + } else if(hasStrings()) { uint32_t which= spanCondition==USET_SPAN_NOT_CONTAINED ? UnicodeSetStringSpan::BACK_UTF16_NOT_CONTAINED : UnicodeSetStringSpan::BACK_UTF16_CONTAINED; @@ -2290,7 +2290,7 @@ int32_t UnicodeSet::spanUTF8(const char *s, int32_t length, USetSpanCondition sp } if(stringSpan!=NULL) { return stringSpan->spanUTF8((const uint8_t *)s, length, spanCondition); - } else if(hasStrings()) { + } else if(hasStrings()) { uint32_t which= spanCondition==USET_SPAN_NOT_CONTAINED ? UnicodeSetStringSpan::FWD_UTF8_NOT_CONTAINED : UnicodeSetStringSpan::FWD_UTF8_CONTAINED; @@ -2328,7 +2328,7 @@ int32_t UnicodeSet::spanBackUTF8(const char *s, int32_t length, USetSpanConditio } if(stringSpan!=NULL) { return stringSpan->spanBackUTF8((const uint8_t *)s, length, spanCondition); - } else if(hasStrings()) { + } else if(hasStrings()) { uint32_t which= spanCondition==USET_SPAN_NOT_CONTAINED ? UnicodeSetStringSpan::BACK_UTF8_NOT_CONTAINED : UnicodeSetStringSpan::BACK_UTF8_CONTAINED; |