summaryrefslogtreecommitdiffstats
path: root/Vector.c
diff options
context:
space:
mode:
authorBenny Baumann <BenBE@geshi.org>2020-10-06 17:10:23 +0200
committercgzones <cgzones@googlemail.com>2020-10-07 12:59:55 +0200
commit1704c29b90535286afde9a42982c6cacc2e94ae2 (patch)
tree4d76168cb19df1a4c18c4b5590a30c785c042410 /Vector.c
parent769df604b20857e896189434f4134fec253744ac (diff)
Use memmove for Vector_take
Doing a quick check with callgrind this gives an average reduction from 1804 cycles/call down to 491 cycles/call on my test system. The average was taken over about 40k calls.
Diffstat (limited to 'Vector.c')
-rw-r--r--Vector.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/Vector.c b/Vector.c
index af219dda..a606894d 100644
--- a/Vector.c
+++ b/Vector.c
@@ -204,8 +204,9 @@ Object* Vector_take(Vector* this, int idx) {
Object* removed = this->array[idx];
//assert (removed != NULL);
this->items--;
- for (int i = idx; i < this->items; i++)
- this->array[i] = this->array[i+1];
+ if(idx < this->items) {
+ memmove(&this->array[idx], &this->array[idx + 1], (this->items - idx) * sizeof(this->array[0]));
+ }
//this->array[this->items] = NULL;
assert(Vector_isConsistent(this));
return removed;

© 2014-2024 Faster IT GmbH | imprint | privacy policy