Cleanup: BLI: use IndexMask forward declaration in CPPType
This avoids recursive dependencies when we want to make it easier to allocate `CPPType` values with e.g. `LinearAllocator` efficiently. Pull Request: https://projects.blender.org/blender/blender/pulls/137678
This commit is contained in:
@@ -73,7 +73,7 @@
|
||||
*/
|
||||
|
||||
#include "BLI_hash.hh"
|
||||
#include "BLI_index_mask.hh"
|
||||
#include "BLI_index_mask_fwd.hh"
|
||||
#include "BLI_map.hh"
|
||||
#include "BLI_parameter_pack_utils.hh"
|
||||
#include "BLI_string_ref.hh"
|
||||
@@ -155,36 +155,47 @@ class CPPType : NonCopyable, NonMovable {
|
||||
uintptr_t alignment_mask_ = 0;
|
||||
|
||||
void (*default_construct_)(void *ptr) = nullptr;
|
||||
void (*default_construct_n_)(void *ptr, int64_t n) = nullptr;
|
||||
void (*default_construct_indices_)(void *ptr, const IndexMask &mask) = nullptr;
|
||||
|
||||
void (*value_initialize_)(void *ptr) = nullptr;
|
||||
void (*value_initialize_n_)(void *ptr, int64_t n) = nullptr;
|
||||
void (*value_initialize_indices_)(void *ptr, const IndexMask &mask) = nullptr;
|
||||
|
||||
void (*destruct_)(void *ptr) = nullptr;
|
||||
void (*destruct_n_)(void *ptr, int64_t n) = nullptr;
|
||||
void (*destruct_indices_)(void *ptr, const IndexMask &mask) = nullptr;
|
||||
|
||||
void (*copy_assign_)(const void *src, void *dst) = nullptr;
|
||||
void (*copy_assign_n_)(const void *src, void *dst, int64_t n) = nullptr;
|
||||
void (*copy_assign_indices_)(const void *src, void *dst, const IndexMask &mask) = nullptr;
|
||||
void (*copy_assign_compressed_)(const void *src, void *dst, const IndexMask &mask) = nullptr;
|
||||
|
||||
void (*copy_construct_)(const void *src, void *dst) = nullptr;
|
||||
void (*copy_construct_n_)(const void *src, void *dst, int64_t n) = nullptr;
|
||||
void (*copy_construct_indices_)(const void *src, void *dst, const IndexMask &mask) = nullptr;
|
||||
void (*copy_construct_compressed_)(const void *src, void *dst, const IndexMask &mask) = nullptr;
|
||||
|
||||
void (*move_assign_)(void *src, void *dst) = nullptr;
|
||||
void (*move_assign_n_)(void *src, void *dst, int64_t n) = nullptr;
|
||||
void (*move_assign_indices_)(void *src, void *dst, const IndexMask &mask) = nullptr;
|
||||
|
||||
void (*move_construct_)(void *src, void *dst) = nullptr;
|
||||
void (*move_construct_n_)(void *src, void *dst, int64_t n) = nullptr;
|
||||
void (*move_construct_indices_)(void *src, void *dst, const IndexMask &mask) = nullptr;
|
||||
|
||||
void (*relocate_assign_)(void *src, void *dst) = nullptr;
|
||||
void (*relocate_assign_n_)(void *src, void *dst, int64_t n) = nullptr;
|
||||
void (*relocate_assign_indices_)(void *src, void *dst, const IndexMask &mask) = nullptr;
|
||||
|
||||
void (*relocate_construct_)(void *src, void *dst) = nullptr;
|
||||
void (*relocate_construct_n_)(void *src, void *dst, int64_t n) = nullptr;
|
||||
void (*relocate_construct_indices_)(void *src, void *dst, const IndexMask &mask) = nullptr;
|
||||
|
||||
void (*fill_assign_n_)(const void *value, void *dst, int64_t n) = nullptr;
|
||||
void (*fill_assign_indices_)(const void *value, void *dst, const IndexMask &mask) = nullptr;
|
||||
|
||||
void (*fill_construct_n_)(const void *value, void *dst, int64_t n) = nullptr;
|
||||
void (*fill_construct_indices_)(const void *value, void *dst, const IndexMask &mask) = nullptr;
|
||||
|
||||
void (*print_)(const void *value, std::stringstream &ss) = nullptr;
|
||||
@@ -494,7 +505,7 @@ inline void CPPType::default_construct(void *ptr) const
|
||||
|
||||
inline void CPPType::default_construct_n(void *ptr, int64_t n) const
|
||||
{
|
||||
this->default_construct_indices(ptr, IndexMask(n));
|
||||
default_construct_n_(ptr, n);
|
||||
}
|
||||
|
||||
inline void CPPType::default_construct_indices(void *ptr, const IndexMask &mask) const
|
||||
@@ -509,7 +520,7 @@ inline void CPPType::value_initialize(void *ptr) const
|
||||
|
||||
inline void CPPType::value_initialize_n(void *ptr, int64_t n) const
|
||||
{
|
||||
this->value_initialize_indices(ptr, IndexMask(n));
|
||||
value_initialize_n_(ptr, n);
|
||||
}
|
||||
|
||||
inline void CPPType::value_initialize_indices(void *ptr, const IndexMask &mask) const
|
||||
@@ -524,7 +535,7 @@ inline void CPPType::destruct(void *ptr) const
|
||||
|
||||
inline void CPPType::destruct_n(void *ptr, int64_t n) const
|
||||
{
|
||||
this->destruct_indices(ptr, IndexMask(n));
|
||||
destruct_n_(ptr, n);
|
||||
}
|
||||
|
||||
inline void CPPType::destruct_indices(void *ptr, const IndexMask &mask) const
|
||||
@@ -539,7 +550,7 @@ inline void CPPType::copy_assign(const void *src, void *dst) const
|
||||
|
||||
inline void CPPType::copy_assign_n(const void *src, void *dst, int64_t n) const
|
||||
{
|
||||
this->copy_assign_indices(src, dst, IndexMask(n));
|
||||
copy_assign_n_(src, dst, n);
|
||||
}
|
||||
|
||||
inline void CPPType::copy_assign_indices(const void *src, void *dst, const IndexMask &mask) const
|
||||
@@ -561,7 +572,7 @@ inline void CPPType::copy_construct(const void *src, void *dst) const
|
||||
|
||||
inline void CPPType::copy_construct_n(const void *src, void *dst, int64_t n) const
|
||||
{
|
||||
this->copy_construct_indices(src, dst, IndexMask(n));
|
||||
copy_construct_n_(src, dst, n);
|
||||
}
|
||||
|
||||
inline void CPPType::copy_construct_indices(const void *src,
|
||||
@@ -585,7 +596,7 @@ inline void CPPType::move_assign(void *src, void *dst) const
|
||||
|
||||
inline void CPPType::move_assign_n(void *src, void *dst, int64_t n) const
|
||||
{
|
||||
this->move_assign_indices(src, dst, IndexMask(n));
|
||||
move_assign_n_(src, dst, n);
|
||||
}
|
||||
|
||||
inline void CPPType::move_assign_indices(void *src, void *dst, const IndexMask &mask) const
|
||||
@@ -600,7 +611,7 @@ inline void CPPType::move_construct(void *src, void *dst) const
|
||||
|
||||
inline void CPPType::move_construct_n(void *src, void *dst, int64_t n) const
|
||||
{
|
||||
this->move_construct_indices(src, dst, IndexMask(n));
|
||||
move_construct_n_(src, dst, n);
|
||||
}
|
||||
|
||||
inline void CPPType::move_construct_indices(void *src, void *dst, const IndexMask &mask) const
|
||||
@@ -615,7 +626,7 @@ inline void CPPType::relocate_assign(void *src, void *dst) const
|
||||
|
||||
inline void CPPType::relocate_assign_n(void *src, void *dst, int64_t n) const
|
||||
{
|
||||
this->relocate_assign_indices(src, dst, IndexMask(n));
|
||||
relocate_assign_n_(src, dst, n);
|
||||
}
|
||||
|
||||
inline void CPPType::relocate_assign_indices(void *src, void *dst, const IndexMask &mask) const
|
||||
@@ -630,7 +641,7 @@ inline void CPPType::relocate_construct(void *src, void *dst) const
|
||||
|
||||
inline void CPPType::relocate_construct_n(void *src, void *dst, int64_t n) const
|
||||
{
|
||||
this->relocate_construct_indices(src, dst, IndexMask(n));
|
||||
relocate_construct_n_(src, dst, n);
|
||||
}
|
||||
|
||||
inline void CPPType::relocate_construct_indices(void *src, void *dst, const IndexMask &mask) const
|
||||
@@ -640,7 +651,7 @@ inline void CPPType::relocate_construct_indices(void *src, void *dst, const Inde
|
||||
|
||||
inline void CPPType::fill_assign_n(const void *value, void *dst, int64_t n) const
|
||||
{
|
||||
this->fill_assign_indices(value, dst, IndexMask(n));
|
||||
fill_assign_n_(value, dst, n);
|
||||
}
|
||||
|
||||
inline void CPPType::fill_assign_indices(const void *value, void *dst, const IndexMask &mask) const
|
||||
@@ -650,7 +661,7 @@ inline void CPPType::fill_assign_indices(const void *value, void *dst, const Ind
|
||||
|
||||
inline void CPPType::fill_construct_n(const void *value, void *dst, int64_t n) const
|
||||
{
|
||||
this->fill_construct_indices(value, dst, IndexMask(n));
|
||||
fill_construct_n_(value, dst, n);
|
||||
}
|
||||
|
||||
inline void CPPType::fill_construct_indices(const void *value,
|
||||
|
||||
@@ -8,10 +8,12 @@
|
||||
* \ingroup bli
|
||||
*/
|
||||
|
||||
#include "BLI_cpp_type.hh"
|
||||
#include "BLI_utildefines.h"
|
||||
#include <sstream>
|
||||
|
||||
#include "BLI_cpp_type.hh"
|
||||
#include "BLI_index_mask.hh"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
namespace blender::cpp_type_util {
|
||||
|
||||
template<typename T> inline bool pointer_has_valid_alignment(const void *ptr)
|
||||
@@ -37,18 +39,25 @@ template<typename T> void default_construct_indices_cb(void *ptr, const IndexMas
|
||||
}
|
||||
mask.foreach_index_optimized<int64_t>([&](int64_t i) { new (static_cast<T *>(ptr) + i) T; });
|
||||
}
|
||||
template<typename T> void default_construct_n_cb(void *ptr, const int64_t n)
|
||||
{
|
||||
default_construct_indices_cb<T>(ptr, IndexMask(n));
|
||||
}
|
||||
|
||||
template<typename T> void value_initialize_cb(void *ptr)
|
||||
{
|
||||
BLI_assert(pointer_can_point_to_instance<T>(ptr));
|
||||
new (ptr) T();
|
||||
}
|
||||
|
||||
template<typename T> void value_initialize_indices_cb(void *ptr, const IndexMask &mask)
|
||||
{
|
||||
BLI_assert(mask.size() == 0 || pointer_can_point_to_instance<T>(ptr));
|
||||
mask.foreach_index_optimized<int64_t>([&](int64_t i) { new (static_cast<T *>(ptr) + i) T(); });
|
||||
}
|
||||
template<typename T> void value_initialize_n_cb(void *ptr, const int64_t n)
|
||||
{
|
||||
value_initialize_indices_cb<T>(ptr, IndexMask(n));
|
||||
}
|
||||
|
||||
template<typename T> void destruct_cb(void *ptr)
|
||||
{
|
||||
@@ -64,6 +73,10 @@ template<typename T> void destruct_indices_cb(void *ptr, const IndexMask &mask)
|
||||
T *ptr_ = static_cast<T *>(ptr);
|
||||
mask.foreach_index_optimized<int64_t>([&](int64_t i) { ptr_[i].~T(); });
|
||||
}
|
||||
template<typename T> void destruct_n_cb(void *ptr, const int64_t n)
|
||||
{
|
||||
destruct_indices_cb<T>(ptr, IndexMask(n));
|
||||
}
|
||||
|
||||
template<typename T> void copy_assign_cb(const void *src, void *dst)
|
||||
{
|
||||
@@ -81,6 +94,10 @@ template<typename T> void copy_assign_indices_cb(const void *src, void *dst, con
|
||||
|
||||
mask.foreach_index_optimized<int64_t>([&](int64_t i) { dst_[i] = src_[i]; });
|
||||
}
|
||||
template<typename T> void copy_assign_n_cb(const void *src, void *dst, const int64_t n)
|
||||
{
|
||||
copy_assign_indices_cb<T>(src, dst, IndexMask(n));
|
||||
}
|
||||
template<typename T>
|
||||
void copy_assign_compressed_cb(const void *src, void *dst, const IndexMask &mask)
|
||||
{
|
||||
@@ -112,6 +129,10 @@ void copy_construct_indices_cb(const void *src, void *dst, const IndexMask &mask
|
||||
|
||||
mask.foreach_index_optimized<int64_t>([&](int64_t i) { new (dst_ + i) T(src_[i]); });
|
||||
}
|
||||
template<typename T> void copy_construct_n_cb(const void *src, void *dst, const int64_t n)
|
||||
{
|
||||
copy_construct_indices_cb<T>(src, dst, IndexMask(n));
|
||||
}
|
||||
template<typename T>
|
||||
void copy_construct_compressed_cb(const void *src, void *dst, const IndexMask &mask)
|
||||
{
|
||||
@@ -141,6 +162,10 @@ template<typename T> void move_assign_indices_cb(void *src, void *dst, const Ind
|
||||
|
||||
mask.foreach_index_optimized<int64_t>([&](int64_t i) { dst_[i] = std::move(src_[i]); });
|
||||
}
|
||||
template<typename T> void move_assign_n_cb(void *src, void *dst, const int64_t n)
|
||||
{
|
||||
move_assign_indices_cb<T>(src, dst, IndexMask(n));
|
||||
}
|
||||
|
||||
template<typename T> void move_construct_cb(void *src, void *dst)
|
||||
{
|
||||
@@ -160,6 +185,10 @@ template<typename T> void move_construct_indices_cb(void *src, void *dst, const
|
||||
|
||||
mask.foreach_index_optimized<int64_t>([&](int64_t i) { new (dst_ + i) T(std::move(src_[i])); });
|
||||
}
|
||||
template<typename T> void move_construct_n_cb(void *src, void *dst, const int64_t n)
|
||||
{
|
||||
move_construct_indices_cb<T>(src, dst, IndexMask(n));
|
||||
}
|
||||
|
||||
template<typename T> void relocate_assign_cb(void *src, void *dst)
|
||||
{
|
||||
@@ -185,6 +214,10 @@ template<typename T> void relocate_assign_indices_cb(void *src, void *dst, const
|
||||
src_[i].~T();
|
||||
});
|
||||
}
|
||||
template<typename T> void relocate_assign_n_cb(void *src, void *dst, const int64_t n)
|
||||
{
|
||||
relocate_assign_indices_cb<T>(src, dst, IndexMask(n));
|
||||
}
|
||||
|
||||
template<typename T> void relocate_construct_cb(void *src, void *dst)
|
||||
{
|
||||
@@ -211,6 +244,10 @@ void relocate_construct_indices_cb(void *src, void *dst, const IndexMask &mask)
|
||||
src_[i].~T();
|
||||
});
|
||||
}
|
||||
template<typename T> void relocate_construct_n_cb(void *src, void *dst, const int64_t n)
|
||||
{
|
||||
relocate_construct_indices_cb<T>(src, dst, IndexMask(n));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void fill_assign_indices_cb(const void *value, void *dst, const IndexMask &mask)
|
||||
@@ -222,6 +259,10 @@ void fill_assign_indices_cb(const void *value, void *dst, const IndexMask &mask)
|
||||
|
||||
mask.foreach_index_optimized<int64_t>([&](int64_t i) { dst_[i] = value_; });
|
||||
}
|
||||
template<typename T> void fill_assign_n_cb(const void *value, void *dst, const int64_t n)
|
||||
{
|
||||
fill_assign_indices_cb<T>(value, dst, IndexMask(n));
|
||||
}
|
||||
|
||||
template<typename T> void fill_construct_cb(const void *value, void *dst, int64_t n)
|
||||
{
|
||||
@@ -240,6 +281,10 @@ void fill_construct_indices_cb(const void *value, void *dst, const IndexMask &ma
|
||||
|
||||
mask.foreach_index_optimized<int64_t>([&](int64_t i) { new (dst_ + i) T(value_); });
|
||||
}
|
||||
template<typename T> void fill_construct_n_cb(const void *value, void *dst, const int64_t n)
|
||||
{
|
||||
fill_construct_indices_cb<T>(value, dst, IndexMask(n));
|
||||
}
|
||||
|
||||
template<typename T> void print_cb(const void *value, std::stringstream &ss)
|
||||
{
|
||||
@@ -281,8 +326,10 @@ CPPType::CPPType(TypeTag<T> /*type*/,
|
||||
this->is_trivially_destructible = std::is_trivially_destructible_v<T>;
|
||||
if constexpr (std::is_default_constructible_v<T>) {
|
||||
default_construct_ = default_construct_cb<T>;
|
||||
default_construct_n_ = default_construct_n_cb<T>;
|
||||
default_construct_indices_ = default_construct_indices_cb<T>;
|
||||
value_initialize_ = value_initialize_cb<T>;
|
||||
value_initialize_n_ = value_initialize_n_cb<T>;
|
||||
value_initialize_indices_ = value_initialize_indices_cb<T>;
|
||||
if constexpr (bool(Flags & CPPTypeFlags::IdentityDefaultValue)) {
|
||||
static const T default_value = T::identity();
|
||||
@@ -295,21 +342,25 @@ CPPType::CPPType(TypeTag<T> /*type*/,
|
||||
}
|
||||
if constexpr (std::is_destructible_v<T>) {
|
||||
destruct_ = destruct_cb<T>;
|
||||
destruct_n_ = destruct_n_cb<T>;
|
||||
destruct_indices_ = destruct_indices_cb<T>;
|
||||
}
|
||||
if constexpr (std::is_copy_assignable_v<T>) {
|
||||
copy_assign_ = copy_assign_cb<T>;
|
||||
copy_assign_n_ = copy_assign_n_cb<T>;
|
||||
copy_assign_indices_ = copy_assign_indices_cb<T>;
|
||||
copy_assign_compressed_ = copy_assign_compressed_cb<T>;
|
||||
}
|
||||
if constexpr (std::is_copy_constructible_v<T>) {
|
||||
if constexpr (std::is_trivially_copy_constructible_v<T>) {
|
||||
copy_construct_ = copy_assign_;
|
||||
copy_construct_n_ = copy_assign_n_;
|
||||
copy_construct_indices_ = copy_assign_indices_;
|
||||
copy_construct_compressed_ = copy_assign_compressed_;
|
||||
}
|
||||
else {
|
||||
copy_construct_ = copy_construct_cb<T>;
|
||||
copy_construct_n_ = copy_construct_n_cb<T>;
|
||||
copy_construct_indices_ = copy_construct_indices_cb<T>;
|
||||
copy_construct_compressed_ = copy_construct_compressed_cb<T>;
|
||||
}
|
||||
@@ -319,51 +370,62 @@ CPPType::CPPType(TypeTag<T> /*type*/,
|
||||
/* This casts away the const from the src pointer. This is fine for trivial types as moving
|
||||
* them does not change the original value. */
|
||||
move_assign_ = reinterpret_cast<decltype(move_assign_)>(copy_assign_);
|
||||
move_assign_n_ = reinterpret_cast<decltype(move_assign_n_)>(copy_assign_n_);
|
||||
move_assign_indices_ = reinterpret_cast<decltype(move_assign_indices_)>(
|
||||
copy_assign_indices_);
|
||||
}
|
||||
else {
|
||||
move_assign_ = move_assign_cb<T>;
|
||||
move_assign_n_ = move_assign_n_cb<T>;
|
||||
move_assign_indices_ = move_assign_indices_cb<T>;
|
||||
}
|
||||
}
|
||||
if constexpr (std::is_move_constructible_v<T>) {
|
||||
if constexpr (std::is_trivially_move_constructible_v<T>) {
|
||||
move_construct_ = move_assign_;
|
||||
move_construct_n_ = move_assign_n_;
|
||||
move_construct_indices_ = move_assign_indices_;
|
||||
}
|
||||
else {
|
||||
move_construct_ = move_construct_cb<T>;
|
||||
move_construct_n_ = move_construct_n_cb<T>;
|
||||
move_construct_indices_ = move_construct_indices_cb<T>;
|
||||
}
|
||||
}
|
||||
if constexpr (std::is_destructible_v<T>) {
|
||||
if constexpr (std::is_trivially_move_assignable_v<T> && std::is_trivially_destructible_v<T>) {
|
||||
relocate_assign_ = move_assign_;
|
||||
relocate_assign_n_ = move_assign_n_;
|
||||
relocate_assign_indices_ = move_assign_indices_;
|
||||
|
||||
relocate_construct_ = move_assign_;
|
||||
relocate_construct_n_ = move_assign_n_;
|
||||
relocate_construct_indices_ = move_assign_indices_;
|
||||
}
|
||||
else {
|
||||
if constexpr (std::is_move_assignable_v<T>) {
|
||||
relocate_assign_ = relocate_assign_cb<T>;
|
||||
relocate_assign_n_ = relocate_assign_n_cb<T>;
|
||||
relocate_assign_indices_ = relocate_assign_indices_cb<T>;
|
||||
}
|
||||
if constexpr (std::is_move_constructible_v<T>) {
|
||||
relocate_construct_ = relocate_construct_cb<T>;
|
||||
relocate_construct_n_ = relocate_construct_n_cb<T>;
|
||||
relocate_construct_indices_ = relocate_construct_indices_cb<T>;
|
||||
}
|
||||
}
|
||||
}
|
||||
if constexpr (std::is_copy_assignable_v<T>) {
|
||||
fill_assign_n_ = fill_assign_n_cb<T>;
|
||||
fill_assign_indices_ = fill_assign_indices_cb<T>;
|
||||
}
|
||||
if constexpr (std::is_copy_constructible_v<T>) {
|
||||
if constexpr (std::is_trivially_constructible_v<T>) {
|
||||
fill_construct_n_ = fill_assign_n_;
|
||||
fill_construct_indices_ = fill_assign_indices_;
|
||||
}
|
||||
else {
|
||||
fill_construct_n_ = fill_construct_n_cb<T>;
|
||||
fill_construct_indices_ = fill_construct_indices_cb<T>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "BLI_compute_context.hh"
|
||||
#include "BLI_generic_pointer.hh"
|
||||
#include "BLI_resource_scope.hh"
|
||||
#include "BLI_vector_set.hh"
|
||||
|
||||
#include "DNA_node_types.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user