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)) {
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;
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 true;
}
+
/**
* Change the size of this vector as follows: If newSize is smaller,
* then truncate the array, possibly deleting held elements for i >=
// 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,
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);
/**