From 164051354f11c0426e09e4fa09feeca7de92e619 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Tue, 6 Oct 2020 17:19:40 +0200 Subject: Replace copy loop by memmove in Vector_insert This is basically the same change like in Vector_take, just in the opposite direction. --- Vector.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Vector.c') diff --git a/Vector.c b/Vector.c index a606894d..3d4e6466 100644 --- a/Vector.c +++ b/Vector.c @@ -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++; -- cgit v1.2.3