BLI: optimize Map/Set/VectorSet.clear methods
Previously, those methods would destruct and reconstruct the data structure. While that was more simple in initial implementation, it has some downsides which are not resolved: * Already allocated memory is lost. So new memory would have to be allocated when the data structure is refilled. * The clearing process itself was slower because it did unnecessary work.
This commit is contained in:
parent
29d9bb89ce
commit
a264dff4fa
|
@ -962,7 +962,13 @@ class Map {
|
|||
*/
|
||||
void clear()
|
||||
{
|
||||
this->noexcept_reset();
|
||||
for (Slot &slot : slots_) {
|
||||
slot.~Slot();
|
||||
new (&slot) Slot();
|
||||
}
|
||||
|
||||
removed_slots_ = 0;
|
||||
occupied_and_removed_slots_ = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -515,8 +515,13 @@ class Set {
|
|||
*/
|
||||
void clear()
|
||||
{
|
||||
this->~Set();
|
||||
new (this) Set();
|
||||
for (Slot &slot : slots_) {
|
||||
slot.~Slot();
|
||||
new (&slot) Slot();
|
||||
}
|
||||
|
||||
removed_slots_ = 0;
|
||||
occupied_and_removed_slots_ = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -531,7 +531,14 @@ class VectorSet {
|
|||
*/
|
||||
void clear()
|
||||
{
|
||||
this->noexcept_reset();
|
||||
destruct_n(keys_, this->size());
|
||||
for (Slot &slot : slots_) {
|
||||
slot.~Slot();
|
||||
new (&slot) Slot();
|
||||
}
|
||||
|
||||
removed_slots_ = 0;
|
||||
occupied_and_removed_slots_ = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue