Skip to content

Commit

Permalink
8312395: Improve assertions in growableArray
Browse files Browse the repository at this point in the history
Reviewed-by: clanger
Backport-of: b772e67
  • Loading branch information
MBaesken committed Oct 20, 2023
1 parent 05c6ae4 commit e80200f
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/hotspot/share/utilities/growableArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,17 @@ class GrowableArrayView : public GrowableArrayBase {
}

E& at(int i) {
assert(0 <= i && i < _len, "illegal index");
assert(0 <= i && i < _len, "illegal index %d for length %d", i, _len);
return _data[i];
}

E const& at(int i) const {
assert(0 <= i && i < _len, "illegal index");
assert(0 <= i && i < _len, "illegal index %d for length %d", i, _len);
return _data[i];
}

E* adr_at(int i) const {
assert(0 <= i && i < _len, "illegal index");
assert(0 <= i && i < _len, "illegal index %d for length %d", i, _len);
return &_data[i];
}

Expand Down Expand Up @@ -184,7 +184,7 @@ class GrowableArrayView : public GrowableArrayBase {
}

void at_put(int i, const E& elem) {
assert(0 <= i && i < _len, "illegal index");
assert(0 <= i && i < _len, "illegal index %d for length %d", i, _len);
_data[i] = elem;
}

Expand Down Expand Up @@ -245,7 +245,7 @@ class GrowableArrayView : public GrowableArrayBase {
}

void remove_at(int index) {
assert(0 <= index && index < _len, "illegal index");
assert(0 <= index && index < _len, "illegal index %d for length %d", index, _len);
for (int j = index + 1; j < _len; j++) {
_data[j-1] = _data[j];
}
Expand All @@ -262,7 +262,7 @@ class GrowableArrayView : public GrowableArrayBase {

// The order is changed.
void delete_at(int index) {
assert(0 <= index && index < _len, "illegal index");
assert(0 <= index && index < _len, "illegal index %d for length %d", index, _len);
if (index < --_len) {
// Replace removed element with last one.
_data[index] = _data[_len];
Expand Down Expand Up @@ -390,7 +390,7 @@ class GrowableArrayWithAllocator : public GrowableArrayView<E> {
void push(const E& elem) { append(elem); }

E at_grow(int i, const E& fill = E()) {
assert(0 <= i, "negative index");
assert(0 <= i, "negative index %d", i);
if (i >= this->_len) {
if (i >= this->_max) grow(i);
for (int j = this->_len; j <= i; j++)
Expand All @@ -401,7 +401,7 @@ class GrowableArrayWithAllocator : public GrowableArrayView<E> {
}

void at_put_grow(int i, const E& elem, const E& fill = E()) {
assert(0 <= i, "negative index");
assert(0 <= i, "negative index %d", i);
if (i >= this->_len) {
if (i >= this->_max) grow(i);
for (int j = this->_len; j < i; j++)
Expand All @@ -413,7 +413,7 @@ class GrowableArrayWithAllocator : public GrowableArrayView<E> {

// inserts the given element before the element at index i
void insert_before(const int idx, const E& elem) {
assert(0 <= idx && idx <= this->_len, "illegal index");
assert(0 <= idx && idx <= this->_len, "illegal index %d for length %d", idx, this->_len);
if (this->_len == this->_max) grow(this->_len);
for (int j = this->_len - 1; j >= idx; j--) {
this->_data[j + 1] = this->_data[j];
Expand All @@ -423,7 +423,7 @@ class GrowableArrayWithAllocator : public GrowableArrayView<E> {
}

void insert_before(const int idx, const GrowableArrayView<E>* array) {
assert(0 <= idx && idx <= this->_len, "illegal index");
assert(0 <= idx && idx <= this->_len, "illegal index %d for length %d", idx, this->_len);
int array_len = array->length();
int new_len = this->_len + array_len;
if (new_len >= this->_max) grow(new_len);
Expand Down

0 comments on commit e80200f

Please sign in to comment.