mirror of https://github.com/xzeldon/htop.git
Hashtable: skip rehashing if the size is the same
Hashtable_setSize should not rehash if the actual size stays the same as the number of buckets and natural positions stay the same too.
This commit is contained in:
parent
bc08c7dc2a
commit
d084a80023
|
@ -191,10 +191,14 @@ void Hashtable_setSize(Hashtable* this, size_t size) {
|
||||||
if (size <= this->items)
|
if (size <= this->items)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
size_t newSize = nextPrime(size);
|
||||||
|
if (newSize == this->size)
|
||||||
|
return;
|
||||||
|
|
||||||
HashtableItem* oldBuckets = this->buckets;
|
HashtableItem* oldBuckets = this->buckets;
|
||||||
size_t oldSize = this->size;
|
size_t oldSize = this->size;
|
||||||
|
|
||||||
this->size = nextPrime(size);
|
this->size = newSize;
|
||||||
this->buckets = (HashtableItem*) xCalloc(this->size, sizeof(HashtableItem));
|
this->buckets = (HashtableItem*) xCalloc(this->size, sizeof(HashtableItem));
|
||||||
this->items = 0;
|
this->items = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue