Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-06-09 11:10:56 +0300
committerJacques Lucke <jacques@blender.org>2020-06-09 11:15:43 +0300
commitd8678e02ecec9375bec1dcf1388c6fc8b4ce3ad2 (patch)
tree6e7d2a7452091877f73d413d830e6cb12e86745f /source/blender/functions
parent50258d55e7c1360274d40e303386cf70b16c8b2f (diff)
BLI: generally improve C++ data structures
The main focus here was to improve the docs significantly. Furthermore, I reimplemented `Set`, `Map` and `VectorSet`. They are now (usually) faster, simpler and more customizable. I also rewrote `Stack` to make it more efficient by avoiding unnecessary copies. Thanks to everyone who helped with constructive feedback. Approved by brecht and sybren. Differential Revision: https://developer.blender.org/D7931
Diffstat (limited to 'source/blender/functions')
-rw-r--r--source/blender/functions/FN_cpp_type.hh27
1 files changed, 17 insertions, 10 deletions
diff --git a/source/blender/functions/FN_cpp_type.hh b/source/blender/functions/FN_cpp_type.hh
index 10e95c0341e..df6da7a3f47 100644
--- a/source/blender/functions/FN_cpp_type.hh
+++ b/source/blender/functions/FN_cpp_type.hh
@@ -534,22 +534,20 @@ namespace CPPTypeUtil {
template<typename T> void construct_default_cb(void *ptr)
{
- BLI::construct_default((T *)ptr);
+ new (ptr) T;
}
template<typename T> void construct_default_n_cb(void *ptr, uint n)
{
- for (uint i = 0; i < n; i++) {
- BLI::construct_default((T *)ptr + i);
- }
+ BLI::default_construct_n((T *)ptr, n);
}
template<typename T> void construct_default_indices_cb(void *ptr, IndexMask index_mask)
{
- index_mask.foreach_index([&](uint i) { BLI::construct_default((T *)ptr + i); });
+ index_mask.foreach_index([&](uint i) { new ((T *)ptr + i) T; });
}
template<typename T> void destruct_cb(void *ptr)
{
- BLI::destruct((T *)ptr);
+ ((T *)ptr)->~T();
}
template<typename T> void destruct_n_cb(void *ptr, uint n)
{
@@ -557,7 +555,8 @@ template<typename T> void destruct_n_cb(void *ptr, uint n)
}
template<typename T> void destruct_indices_cb(void *ptr, IndexMask index_mask)
{
- index_mask.foreach_index([&](uint i) { BLI::destruct((T *)ptr + i); });
+ T *ptr_ = (T *)ptr;
+ index_mask.foreach_index([&](uint i) { ptr_[i].~T(); });
}
template<typename T> void copy_to_initialized_cb(const void *src, void *dst)
@@ -601,11 +600,15 @@ void copy_to_uninitialized_indices_cb(const void *src, void *dst, IndexMask inde
template<typename T> void relocate_to_initialized_cb(void *src, void *dst)
{
- BLI::relocate((T *)src, (T *)dst);
+ T *src_ = (T *)src;
+ T *dst_ = (T *)dst;
+
+ *dst_ = std::move(*src_);
+ src_->~T();
}
template<typename T> void relocate_to_initialized_n_cb(void *src, void *dst, uint n)
{
- BLI::relocate_n((T *)src, n, (T *)dst);
+ BLI::initialized_relocate_n((T *)src, n, (T *)dst);
}
template<typename T>
void relocate_to_initialized_indices_cb(void *src, void *dst, IndexMask index_mask)
@@ -621,7 +624,11 @@ void relocate_to_initialized_indices_cb(void *src, void *dst, IndexMask index_ma
template<typename T> void relocate_to_uninitialized_cb(void *src, void *dst)
{
- BLI::uninitialized_relocate((T *)src, (T *)dst);
+ T *src_ = (T *)src;
+ T *dst_ = (T *)dst;
+
+ new (dst_) T(std::move(*src_));
+ src_->~T();
}
template<typename T> void relocate_to_uninitialized_n_cb(void *src, void *dst, uint n)
{