Skip to content

Commit

Permalink
Replace copy loop by memmove in Vector_insert
Browse files Browse the repository at this point in the history
This is basically the same change like in Vector_take,
just in the opposite direction.
  • Loading branch information
BenBE authored and cgzones committed Oct 7, 2020
1 parent 1704c29 commit 1640513
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ void Vector_insert(Vector* this, int idx, void* data_) {

Vector_checkArraySize(this);
//assert(this->array[this->items] == NULL);
for (int i = this->items; i > idx; i--) {
this->array[i] = this->array[i-1];
if(idx < this->items) {
memmove(&this->array[idx + 1], &this->array[idx], (this->items - idx) * sizeof(this->array[0]));
}
this->array[idx] = data;
this->items++;
Expand Down

0 comments on commit 1640513

Please sign in to comment.