[Bf-blender-cvs] [2225dab8012] functions: optimize fill operation
Jacques Lucke
noreply at git.blender.org
Sat Dec 14 17:45:12 CET 2019
Commit: 2225dab801211b7b017994bff327224c19cfa4a8
Author: Jacques Lucke
Date: Sat Dec 14 17:06:07 2019 +0100
Branches: functions
https://developer.blender.org/rB2225dab801211b7b017994bff327224c19cfa4a8
optimize fill operation
===================================================================
M source/blender/functions/FN_cpp_type.h
M source/blender/functions/FN_generic_array_ref.h
M source/blender/functions/intern/cpp_types.cc
===================================================================
diff --git a/source/blender/functions/FN_cpp_type.h b/source/blender/functions/FN_cpp_type.h
index faf86c2eb89..8a547219429 100644
--- a/source/blender/functions/FN_cpp_type.h
+++ b/source/blender/functions/FN_cpp_type.h
@@ -22,6 +22,8 @@ class CPPType {
using RelocateToInitializedF = void (*)(void *src, void *dst);
using RelocateToUninitializedF = void (*)(void *src, void *dst);
using RelocateToUninitializedNF = void (*)(void *src, void *dst, uint n);
+ using FillInitializedF = void (*)(const void *value, void *dst, uint n);
+ using FillUninitializedF = void (*)(const void *value, void *dst, uint n);
CPPType(std::string name,
uint size,
@@ -37,6 +39,8 @@ class CPPType {
RelocateToInitializedF relocate_to_initialized,
RelocateToUninitializedF relocate_to_uninitialized,
RelocateToUninitializedNF relocate_to_uninitialized_n,
+ FillInitializedF fill_initialized,
+ FillUninitializedF fill_uninitialized,
const CPPType *generalization)
: m_size(size),
m_alignment(alignment),
@@ -51,6 +55,8 @@ class CPPType {
m_relocate_to_initialized(relocate_to_initialized),
m_relocate_to_uninitialized(relocate_to_uninitialized),
m_relocate_to_uninitialized_n(relocate_to_uninitialized_n),
+ m_fill_initialized(fill_initialized),
+ m_fill_uninitialized(fill_uninitialized),
m_generalization(generalization),
m_name(name)
{
@@ -169,6 +175,22 @@ class CPPType {
m_relocate_to_uninitialized_n(src, dst, n);
}
+ void fill_initialized(const void *value, void *dst, uint n) const
+ {
+ BLI_assert(this->pointer_has_valid_alignment(value));
+ BLI_assert(this->pointer_has_valid_alignment(dst));
+
+ m_fill_initialized(value, dst, n);
+ }
+
+ void fill_uninitialized(const void *value, void *dst, uint n) const
+ {
+ BLI_assert(this->pointer_has_valid_alignment(value));
+ BLI_assert(this->pointer_has_valid_alignment(dst));
+
+ m_fill_uninitialized(value, dst, n);
+ }
+
bool is_same_or_generalization(const CPPType &other) const
{
if (&other == this) {
@@ -205,6 +227,8 @@ class CPPType {
RelocateToInitializedF m_relocate_to_initialized;
RelocateToUninitializedF m_relocate_to_uninitialized;
RelocateToUninitializedNF m_relocate_to_uninitialized_n;
+ FillInitializedF m_fill_initialized;
+ FillUninitializedF m_fill_uninitialized;
const CPPType *m_generalization;
std::string m_name;
};
diff --git a/source/blender/functions/FN_generic_array_ref.h b/source/blender/functions/FN_generic_array_ref.h
index 19a795b812d..108322727c6 100644
--- a/source/blender/functions/FN_generic_array_ref.h
+++ b/source/blender/functions/FN_generic_array_ref.h
@@ -135,16 +135,12 @@ class GenericMutableArrayRef {
void fill__uninitialized(const void *value)
{
- for (uint i = 0; i < m_size; i++) {
- m_type->copy_to_uninitialized(value, (*this)[i]);
- }
+ m_type->fill_uninitialized(value, m_buffer, m_size);
}
void fill__initialized(const void *value)
{
- for (uint i = 0; i < m_size; i++) {
- m_type->copy_to_initialized(value, (*this)[i]);
- }
+ m_type->fill_initialized(value, m_buffer, m_size);
}
void copy_in__uninitialized(uint index, const void *src)
diff --git a/source/blender/functions/intern/cpp_types.cc b/source/blender/functions/intern/cpp_types.cc
index fb9f3d47266..9daba16250c 100644
--- a/source/blender/functions/intern/cpp_types.cc
+++ b/source/blender/functions/intern/cpp_types.cc
@@ -59,6 +59,24 @@ template<typename T> void RelocateToUninitializedN_CB(void *src, void *dst, uint
{
BLI::uninitialized_relocate_n((T *)src, n, (T *)dst);
}
+template<typename T> void FillInitialized_CB(const void *value, void *dst, uint n)
+{
+ const T &value_ = *(const T *)value;
+ T *dst_ = (T *)dst;
+
+ for (uint i = 0; i < n; i++) {
+ dst_[i] = value_;
+ }
+}
+template<typename T> void FillUninitialized_CB(const void *value, void *dst, uint n)
+{
+ const T &value_ = *(const T *)value;
+ T *dst_ = (T *)dst;
+
+ for (uint i = 0; i < n; i++) {
+ new (dst_ + i) T(value_);
+ }
+}
template<typename T> static std::unique_ptr<const CPPType> create_cpp_type(StringRef name)
{
@@ -76,6 +94,8 @@ template<typename T> static std::unique_ptr<const CPPType> create_cpp_type(Strin
RelocateToInitialized_CB<T>,
RelocateToUninitialized_CB<T>,
RelocateToUninitializedN_CB<T>,
+ FillInitialized_CB<T>,
+ FillUninitialized_CB<T>,
nullptr);
return std::unique_ptr<const CPPType>(type);
}
More information about the Bf-blender-cvs
mailing list