[Bf-blender-cvs] [bf1791ba92d] master: BLI: add clear-and-shrink method to more data structures
Jacques Lucke
noreply at git.blender.org
Fri Dec 9 12:07:44 CET 2022
Commit: bf1791ba92d280392cc3f00709d7da395b2a58f4
Author: Jacques Lucke
Date: Fri Dec 9 12:00:37 2022 +0100
Branches: master
https://developer.blender.org/rBbf1791ba92d280392cc3f00709d7da395b2a58f4
BLI: add clear-and-shrink method to more data structures
Also renames the existing `clear_and_make_inline` to `clear_and_shrink`
which is more concise.
===================================================================
M source/blender/blenkernel/intern/curves_geometry.cc
M source/blender/blenlib/BLI_map.hh
M source/blender/blenlib/BLI_multi_value_map.hh
M source/blender/blenlib/BLI_set.hh
M source/blender/blenlib/BLI_stack.hh
M source/blender/blenlib/BLI_vector.hh
M source/blender/blenlib/BLI_vector_set.hh
M source/blender/compositor/intern/COM_WorkScheduler.cc
M source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
===================================================================
diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc
index 94ab5ceeace..5cbb0709c91 100644
--- a/source/blender/blenkernel/intern/curves_geometry.cc
+++ b/source/blender/blenkernel/intern/curves_geometry.cc
@@ -519,7 +519,7 @@ void CurvesGeometry::ensure_evaluated_offsets() const
this->runtime->bezier_evaluated_offsets.resize(this->points_num());
}
else {
- this->runtime->bezier_evaluated_offsets.clear_and_make_inline();
+ this->runtime->bezier_evaluated_offsets.clear_and_shrink();
}
calculate_evaluated_offsets(
@@ -605,7 +605,7 @@ Span<float3> CurvesGeometry::evaluated_positions() const
this->runtime->position_cache_mutex.ensure([&]() {
if (this->is_single_type(CURVE_TYPE_POLY)) {
this->runtime->evaluated_positions_span = this->positions();
- this->runtime->evaluated_position_cache.clear_and_make_inline();
+ this->runtime->evaluated_position_cache.clear_and_shrink();
return;
}
diff --git a/source/blender/blenlib/BLI_map.hh b/source/blender/blenlib/BLI_map.hh
index fb048102153..e7958ee49ac 100644
--- a/source/blender/blenlib/BLI_map.hh
+++ b/source/blender/blenlib/BLI_map.hh
@@ -990,6 +990,15 @@ class Map {
occupied_and_removed_slots_ = 0;
}
+ /**
+ * Removes all key-value-pairs from the map and frees any allocated memory.
+ */
+ void clear_and_shrink()
+ {
+ std::destroy_at(this);
+ new (this) Map(NoExceptConstructor{});
+ }
+
/**
* Get the number of collisions that the probing strategy has to go through to find the key or
* determine that it is not in the map.
diff --git a/source/blender/blenlib/BLI_multi_value_map.hh b/source/blender/blenlib/BLI_multi_value_map.hh
index 81b536e7d3c..99fc7dffe3b 100644
--- a/source/blender/blenlib/BLI_multi_value_map.hh
+++ b/source/blender/blenlib/BLI_multi_value_map.hh
@@ -150,6 +150,11 @@ template<typename Key, typename Value> class MultiValueMap {
{
map_.clear();
}
+
+ void clear_and_shrink()
+ {
+ map_.clear_and_shrink();
+ }
};
} // namespace blender
diff --git a/source/blender/blenlib/BLI_set.hh b/source/blender/blenlib/BLI_set.hh
index 548195e48f7..3e5e6fabb42 100644
--- a/source/blender/blenlib/BLI_set.hh
+++ b/source/blender/blenlib/BLI_set.hh
@@ -542,6 +542,15 @@ class Set {
occupied_and_removed_slots_ = 0;
}
+ /**
+ * Removes all keys from the set and frees any allocated memory.
+ */
+ void clear_and_shrink()
+ {
+ std::destroy_at(this);
+ new (this) Set(NoExceptConstructor{});
+ }
+
/**
* Creates a new slot array and reinserts all keys inside of that. This method can be used to get
* rid of removed slots. Also this is useful for benchmarking the grow function.
diff --git a/source/blender/blenlib/BLI_stack.hh b/source/blender/blenlib/BLI_stack.hh
index ed123f43a6b..a9db671e7ac 100644
--- a/source/blender/blenlib/BLI_stack.hh
+++ b/source/blender/blenlib/BLI_stack.hh
@@ -329,6 +329,15 @@ class Stack {
top_ = top_chunk_->begin;
}
+ /**
+ * Removes all elements from the stack and frees any allocated memory.
+ */
+ void clear_and_shrink()
+ {
+ std::destroy_at(this);
+ new (this) Stack(NoExceptConstructor{});
+ }
+
/* This should only be called by unit tests. */
bool is_invariant_maintained() const
{
diff --git a/source/blender/blenlib/BLI_vector.hh b/source/blender/blenlib/BLI_vector.hh
index 6bc785c322a..be594377eb3 100644
--- a/source/blender/blenlib/BLI_vector.hh
+++ b/source/blender/blenlib/BLI_vector.hh
@@ -410,7 +410,7 @@ class Vector {
* Afterwards the vector has 0 elements and any allocated memory
* will be freed.
*/
- void clear_and_make_inline()
+ void clear_and_shrink()
{
destruct_n(begin_, this->size());
if (!this->is_inline()) {
diff --git a/source/blender/blenlib/BLI_vector_set.hh b/source/blender/blenlib/BLI_vector_set.hh
index 9805e8a7d59..1be21ccb5d1 100644
--- a/source/blender/blenlib/BLI_vector_set.hh
+++ b/source/blender/blenlib/BLI_vector_set.hh
@@ -560,6 +560,15 @@ class VectorSet {
occupied_and_removed_slots_ = 0;
}
+ /**
+ * Removes all keys from the set and frees any allocated memory.
+ */
+ void clear_and_shrink()
+ {
+ std::destroy_at(this);
+ new (this) VectorSet(NoExceptConstructor{});
+ }
+
/**
* Get the number of collisions that the probing strategy has to go through to find the key or
* determine that it is not in the set.
diff --git a/source/blender/compositor/intern/COM_WorkScheduler.cc b/source/blender/compositor/intern/COM_WorkScheduler.cc
index 9067807d98c..539d23ff6b5 100644
--- a/source/blender/compositor/intern/COM_WorkScheduler.cc
+++ b/source/blender/compositor/intern/COM_WorkScheduler.cc
@@ -266,7 +266,7 @@ static void opencl_initialize(const bool use_opencl)
static void opencl_deinitialize()
{
- g_work_scheduler.opencl.devices.clear_and_make_inline();
+ g_work_scheduler.opencl.devices.clear_and_shrink();
if (g_work_scheduler.opencl.program) {
clReleaseProgram(g_work_scheduler.opencl.program);
@@ -364,7 +364,7 @@ static void threading_model_queue_deinitialize()
{
/* deinitialize CPU threads */
if (g_work_scheduler.queue.initialized) {
- g_work_scheduler.queue.devices.clear_and_make_inline();
+ g_work_scheduler.queue.devices.clear_and_shrink();
BLI_thread_local_delete(g_thread_device);
g_work_scheduler.queue.initialized = false;
diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
index 86518bd09f2..181180267db 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
@@ -82,11 +82,11 @@ void OBJMesh::clear()
owned_export_mesh_ = nullptr;
}
export_mesh_ = nullptr;
- uv_indices_.clear_and_make_inline();
- uv_coords_.clear_and_make_inline();
- loop_to_normal_index_.clear_and_make_inline();
- normal_coords_.clear_and_make_inline();
- poly_order_.clear_and_make_inline();
+ uv_indices_.clear_and_shrink();
+ uv_coords_.clear_and_shrink();
+ loop_to_normal_index_.clear_and_shrink();
+ normal_coords_.clear_and_shrink();
+ poly_order_.clear_and_shrink();
if (poly_smooth_groups_) {
MEM_freeN(poly_smooth_groups_);
poly_smooth_groups_ = nullptr;
More information about the Bf-blender-cvs
mailing list