[Bf-blender-cvs] [a264dff4fa7] master: BLI: optimize Map/Set/VectorSet.clear methods
Jacques Lucke
noreply at git.blender.org
Tue Mar 29 10:41:12 CEST 2022
Commit: a264dff4fa7dd0bb2e3c9abe805376b730d28c34
Author: Jacques Lucke
Date: Tue Mar 29 10:40:47 2022 +0200
Branches: master
https://developer.blender.org/rBa264dff4fa7dd0bb2e3c9abe805376b730d28c34
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.
===================================================================
M source/blender/blenlib/BLI_map.hh
M source/blender/blenlib/BLI_set.hh
M source/blender/blenlib/BLI_vector_set.hh
===================================================================
diff --git a/source/blender/blenlib/BLI_map.hh b/source/blender/blenlib/BLI_map.hh
index 3cbb81b5c7d..d76aa46502d 100644
--- a/source/blender/blenlib/BLI_map.hh
+++ b/source/blender/blenlib/BLI_map.hh
@@ -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;
}
/**
diff --git a/source/blender/blenlib/BLI_set.hh b/source/blender/blenlib/BLI_set.hh
index bf177802c97..391d31c2228 100644
--- a/source/blender/blenlib/BLI_set.hh
+++ b/source/blender/blenlib/BLI_set.hh
@@ -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;
}
/**
diff --git a/source/blender/blenlib/BLI_vector_set.hh b/source/blender/blenlib/BLI_vector_set.hh
index 23284fd94bc..4ae1bf9000d 100644
--- a/source/blender/blenlib/BLI_vector_set.hh
+++ b/source/blender/blenlib/BLI_vector_set.hh
@@ -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;
}
/**
More information about the Bf-blender-cvs
mailing list