mirror of https://github.com/xzeldon/htop.git
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.
This commit is contained in:
parent
769df604b2
commit
1704c29b90
5
Vector.c
5
Vector.c
|
@ -204,8 +204,9 @@ Object* Vector_take(Vector* this, int idx) {
|
||||||
Object* removed = this->array[idx];
|
Object* removed = this->array[idx];
|
||||||
//assert (removed != NULL);
|
//assert (removed != NULL);
|
||||||
this->items--;
|
this->items--;
|
||||||
for (int i = idx; i < this->items; i++)
|
if(idx < this->items) {
|
||||||
this->array[i] = this->array[i+1];
|
memmove(&this->array[idx], &this->array[idx + 1], (this->items - idx) * sizeof(this->array[0]));
|
||||||
|
}
|
||||||
//this->array[this->items] = NULL;
|
//this->array[this->items] = NULL;
|
||||||
assert(Vector_isConsistent(this));
|
assert(Vector_isConsistent(this));
|
||||||
return removed;
|
return removed;
|
||||||
|
|
Loading…
Reference in New Issue