diff options
author | Benny Baumann <BenBE@geshi.org> | 2020-10-06 17:19:40 +0200 |
---|---|---|
committer | cgzones <cgzones@googlemail.com> | 2020-10-07 12:59:55 +0200 |
commit | 164051354f11c0426e09e4fa09feeca7de92e619 (patch) | |
tree | ed5b79f222088b0502ad83facd79337d2316a17a /Vector.c | |
parent | 1704c29b90535286afde9a42982c6cacc2e94ae2 (diff) |
Replace copy loop by memmove in Vector_insert
This is basically the same change like in Vector_take,
just in the opposite direction.
Diffstat (limited to 'Vector.c')
-rw-r--r-- | Vector.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -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++; |