[Bf-blender-cvs] [13ef2b1065e] functions: remove special type info for lists
Jacques Lucke
noreply at git.blender.org
Sun Mar 24 17:03:19 CET 2019
Commit: 13ef2b1065e9255cd2276e4287873176737bcd2d
Author: Jacques Lucke
Date: Sun Mar 24 17:03:07 2019 +0100
Branches: functions
https://developer.blender.org/rB13ef2b1065e9255cd2276e4287873176737bcd2d
remove special type info for lists
===================================================================
M source/blender/functions/backends/tuple_call/cpp_types.hpp
M source/blender/functions/backends/tuple_call/tuple.hpp
M source/blender/functions/functions/switch.cpp
M source/blender/functions/types/numeric_lists.cpp
===================================================================
diff --git a/source/blender/functions/backends/tuple_call/cpp_types.hpp b/source/blender/functions/backends/tuple_call/cpp_types.hpp
index ae95539d8ff..8af9fb20933 100644
--- a/source/blender/functions/backends/tuple_call/cpp_types.hpp
+++ b/source/blender/functions/backends/tuple_call/cpp_types.hpp
@@ -16,6 +16,8 @@ namespace FN {
virtual void destruct_type(void *ptr) const = 0;
virtual void copy_to_initialized(void *src, void *dst) const = 0;
virtual void copy_to_uninitialized(void *src, void *dst) const = 0;
+ virtual void relocate_to_initialized(void *src, void *dst) const = 0;
+ virtual void relocate_to_uninitialized(void *src, void *dst) const = 0;
};
template<typename T>
@@ -50,6 +52,25 @@ namespace FN {
T *src_ = (T *)src;
std::uninitialized_copy(src_, src_ + 1, dst_);
}
+
+ virtual void relocate_to_initialized(void *src, void *dst) const override
+ {
+ T *dst_ = (T *)dst;
+ T *src_ = (T *)src;
+ *dst_ = std::move(*src_);
+ src_->~T();
+ }
+
+ virtual void relocate_to_uninitialized(void *src, void *dst) const override
+ {
+ T *dst_ = (T *)dst;
+ T *src_ = (T *)src;
+ std::uninitialized_copy(
+ std::make_move_iterator(src_),
+ std::make_move_iterator(src_ + 1),
+ dst_);
+ src_->~T();
+ }
};
} /* namespace FN */
\ No newline at end of file
diff --git a/source/blender/functions/backends/tuple_call/tuple.hpp b/source/blender/functions/backends/tuple_call/tuple.hpp
index a4b59413f78..356d405de45 100644
--- a/source/blender/functions/backends/tuple_call/tuple.hpp
+++ b/source/blender/functions/backends/tuple_call/tuple.hpp
@@ -155,7 +155,7 @@ namespace FN {
m_initialized[index] = true;
}
- inline void move_in__dynamic(uint index, void *src)
+ inline void relocate_in__dynamic(uint index, void *src)
{
BLI_assert(index < m_meta->element_amount());
BLI_assert(src != nullptr);
@@ -164,12 +164,11 @@ namespace FN {
auto *type_info = m_meta->type_infos()[index];
if (m_initialized[index]) {
- type_info->copy_to_initialized(src, dst);
+ type_info->relocate_to_initialized(src, dst);
}
else {
- type_info->copy_to_uninitialized(src, dst);
+ type_info->relocate_to_uninitialized(src, dst);
}
- type_info->destruct_type(src);
m_initialized[index] = true;
}
@@ -215,8 +214,9 @@ namespace FN {
void *src = this->element_ptr(index);
auto *type_info = m_meta->type_infos()[index];
- type_info->copy_to_uninitialized(src, dst);
- type_info->destruct_type(src);
+
+ type_info->relocate_to_uninitialized(src, dst);
+
m_initialized[index] = false;
}
diff --git a/source/blender/functions/functions/switch.cpp b/source/blender/functions/functions/switch.cpp
index 05020f13665..ae0df818802 100644
--- a/source/blender/functions/functions/switch.cpp
+++ b/source/blender/functions/functions/switch.cpp
@@ -26,11 +26,11 @@ namespace FN { namespace Functions {
void *value = alloca(size);
if (condition) {
fn_in.relocate_out__dynamic(1, value);
- fn_out.move_in__dynamic(0, value);
+ fn_out.relocate_in__dynamic(0, value);
}
else {
fn_in.relocate_out__dynamic(2, value);
- fn_out.move_in__dynamic(0, value);
+ fn_out.relocate_in__dynamic(0, value);
}
}
};
diff --git a/source/blender/functions/types/numeric_lists.cpp b/source/blender/functions/types/numeric_lists.cpp
index 2f5705d2012..8eb30c1540c 100644
--- a/source/blender/functions/types/numeric_lists.cpp
+++ b/source/blender/functions/types/numeric_lists.cpp
@@ -7,41 +7,6 @@
namespace FN { namespace Types {
- template<typename T>
- class ListCPPTypeInfo : public CPPTypeInfo {
-
- public:
- uint size_of_type() const override
- {
- static_assert(sizeof(SharedList<T>) == sizeof(void *), "");
- return sizeof(SharedList<T>);
- }
-
- void construct_default(void *ptr) const override
- {
- *(List<T> **)ptr = new List<T>();
- }
-
- void destruct_type(void *ptr) const override
- {
- List<T> *list = *(List<T> **)ptr;
- list->remove_user();
- }
-
- void copy_to_initialized(void *src, void *dst) const override
- {
- this->destruct_type(dst);
- this->copy_to_uninitialized(src, dst);
- }
-
- void copy_to_uninitialized(void *src, void *dst) const override
- {
- List<T> *list = *(List<T> **)src;
- list->new_user();
- *(List<T> **)dst = list;
- }
- };
-
template<typename T>
class ListLLVMTypeInfo : public LLVMTypeInfo {
private:
@@ -77,7 +42,7 @@ namespace FN { namespace Types {
SharedType create_list_type(std::string name)
{
SharedType type = SharedType::New(name);
- type->extend(new ListCPPTypeInfo<T>());
+ type->extend(new CPPTypeInfoForType<SharedList<T>>());
type->extend(ListLLVMTypeInfo<T>::Create());
return type;
}
More information about the Bf-blender-cvs
mailing list