mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-06 22:15:31 +00:00
ICU-21763 UVector cleanup, remove old funcs.
Remove the functions UVector::addElementX() and UVector::ensureCapacityX() that were temporarily added to aid in the cleaning up of UVector's out-of-memory error handling.
This commit is contained in:
parent
fb31d9b54b
commit
2fef6b937f
2 changed files with 2 additions and 53 deletions
|
@ -99,14 +99,6 @@ bool UVector::operator==(const UVector& other) const {
|
|||
return true;
|
||||
}
|
||||
|
||||
// TODO: delete this function once all call sites have been migrated to the
|
||||
// new addElement().
|
||||
void UVector::addElementX(void* obj, UErrorCode &status) {
|
||||
if (ensureCapacityX(count + 1, status)) {
|
||||
elements[count++].pointer = obj;
|
||||
}
|
||||
}
|
||||
|
||||
void UVector::addElement(void* obj, UErrorCode &status) {
|
||||
U_ASSERT(deleter == nullptr);
|
||||
if (ensureCapacity(count + 1, status)) {
|
||||
|
@ -331,38 +323,6 @@ int32_t UVector::indexOf(UElement key, int32_t startIndex, int8_t hint) const {
|
|||
return -1;
|
||||
}
|
||||
|
||||
UBool UVector::ensureCapacityX(int32_t minimumCapacity, UErrorCode &status) {
|
||||
if (minimumCapacity < 0) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return FALSE;
|
||||
}
|
||||
if (capacity < minimumCapacity) {
|
||||
if (capacity > (INT32_MAX - 1) / 2) { // integer overflow check
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return FALSE;
|
||||
}
|
||||
int32_t newCap = capacity * 2;
|
||||
if (newCap < minimumCapacity) {
|
||||
newCap = minimumCapacity;
|
||||
}
|
||||
if (newCap > (int32_t)(INT32_MAX / sizeof(UElement))) { // integer overflow check
|
||||
// We keep the original memory contents on bad minimumCapacity.
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return FALSE;
|
||||
}
|
||||
UElement* newElems = (UElement *)uprv_realloc(elements, sizeof(UElement)*newCap);
|
||||
if (newElems == nullptr) {
|
||||
// We keep the original contents on the memory failure on realloc or bad minimumCapacity.
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
return FALSE;
|
||||
}
|
||||
elements = newElems;
|
||||
capacity = newCap;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
UBool UVector::ensureCapacity(int32_t minimumCapacity, UErrorCode &status) {
|
||||
if (U_FAILURE(status)) {
|
||||
return false;
|
||||
|
@ -370,7 +330,7 @@ UBool UVector::ensureCapacity(int32_t minimumCapacity, UErrorCode &status) {
|
|||
if (minimumCapacity < 0) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (capacity < minimumCapacity) {
|
||||
if (capacity > (INT32_MAX - 1) / 2) { // integer overflow check
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
|
@ -396,6 +356,7 @@ UBool UVector::ensureCapacity(int32_t minimumCapacity, UErrorCode &status) {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the size of this vector as follows: If newSize is smaller,
|
||||
* then truncate the array, possibly deleting held elements for i >=
|
||||
|
|
|
@ -123,12 +123,6 @@ public:
|
|||
// java.util.Vector API
|
||||
//------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Old version of addElement, with non-standard error handling.
|
||||
* Will be removed once all uses have been switched to the new addElement().
|
||||
*/
|
||||
void addElementX(void* obj, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Add an element at the end of the vector.
|
||||
* For use only with vectors that do not adopt their elements, which is to say,
|
||||
|
@ -197,12 +191,6 @@ public:
|
|||
|
||||
inline UBool isEmpty(void) const {return count == 0;}
|
||||
|
||||
/*
|
||||
* Old version of ensureCapacity, with non-standard error handling.
|
||||
* Will be removed once all uses have been switched to the new ensureCapacity().
|
||||
*/
|
||||
UBool ensureCapacityX(int32_t minimumCapacity, UErrorCode &status);
|
||||
|
||||
UBool ensureCapacity(int32_t minimumCapacity, UErrorCode &status);
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue