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 <mail@jlucke.com>2020-02-06 18:44:32 +0300
committerJacques Lucke <mail@jlucke.com>2020-02-06 18:44:32 +0300
commitce14c2c7bd46d8460445bb20d19491b1d1941900 (patch)
treeed501f5a7c1123a470118c912b9938696b3f5dea /source/blender/functions
parent09149b4f0d2c3adec57a93678e357f0a8a87c68a (diff)
store default value per CPPType
Diffstat (limited to 'source/blender/functions')
-rw-r--r--source/blender/functions/FN_attributes_ref.h3
-rw-r--r--source/blender/functions/FN_cpp_type.h10
-rw-r--r--source/blender/functions/intern/cpp_types.cc10
3 files changed, 17 insertions, 6 deletions
diff --git a/source/blender/functions/FN_attributes_ref.h b/source/blender/functions/FN_attributes_ref.h
index cf4a1773f12..3ad29896cc4 100644
--- a/source/blender/functions/FN_attributes_ref.h
+++ b/source/blender/functions/FN_attributes_ref.h
@@ -46,9 +46,8 @@ class AttributesInfoBuilder : BLI::NonCopyable, BLI::NonMovable {
if (m_names.add(name)) {
m_types.append(&type);
void *dst = m_allocator.allocate(type.size(), type.alignment());
- memset(dst, 0, type.size());
if (default_value == nullptr) {
- type.construct_default(dst);
+ type.copy_to_uninitialized(type.default_value(), dst);
}
else {
type.copy_to_uninitialized(default_value, dst);
diff --git a/source/blender/functions/FN_cpp_type.h b/source/blender/functions/FN_cpp_type.h
index fcc2880c3fc..49d5f389b6a 100644
--- a/source/blender/functions/FN_cpp_type.h
+++ b/source/blender/functions/FN_cpp_type.h
@@ -71,7 +71,8 @@ class CPPType {
FillInitializedIndicesF fill_initialized_indices,
FillUninitializedF fill_uninitialized,
FillUninitializedIndicesF fill_uninitialized_indices,
- uint32_t type_hash)
+ uint32_t type_hash,
+ const void *default_value)
: m_size(size),
m_alignment(alignment),
m_trivially_destructible(trivially_destructible),
@@ -98,6 +99,7 @@ class CPPType {
m_fill_uninitialized(fill_uninitialized),
m_fill_uninitialized_indices(fill_uninitialized_indices),
m_type_hash(type_hash),
+ m_default_value(default_value),
m_name(name)
{
BLI_assert(is_power_of_2_i(m_alignment));
@@ -305,6 +307,11 @@ class CPPType {
m_fill_uninitialized_indices(value, dst, index_mask);
}
+ const void *default_value() const
+ {
+ return m_default_value;
+ }
+
uint32_t type_hash() const
{
return m_type_hash;
@@ -357,6 +364,7 @@ class CPPType {
FillUninitializedIndicesF m_fill_uninitialized_indices;
uint32_t m_type_hash;
+ const void *m_default_value;
std::string m_name;
};
diff --git a/source/blender/functions/intern/cpp_types.cc b/source/blender/functions/intern/cpp_types.cc
index cd523cfec9f..22d23e7961c 100644
--- a/source/blender/functions/intern/cpp_types.cc
+++ b/source/blender/functions/intern/cpp_types.cc
@@ -160,7 +160,9 @@ void FillUninitializedIndices_CB(const void *value, void *dst, IndexMask index_m
}
template<typename T>
-static std::unique_ptr<const CPPType> create_cpp_type(StringRef name, uint32_t type_hash)
+static std::unique_ptr<const CPPType> create_cpp_type(StringRef name,
+ uint32_t type_hash,
+ const T &default_value)
{
const CPPType *type = new CPPType(name,
sizeof(T),
@@ -188,13 +190,15 @@ static std::unique_ptr<const CPPType> create_cpp_type(StringRef name, uint32_t t
FillInitializedIndices_CB<T>,
FillUninitialized_CB<T>,
FillUninitializedIndices_CB<T>,
- type_hash);
+ type_hash,
+ (const void *)&default_value);
return std::unique_ptr<const CPPType>(type);
}
#define MAKE_CPP_TYPE(IDENTIFIER, TYPE_NAME) \
+ static TYPE_NAME default_value_##IDENTIFIER; \
static std::unique_ptr<const CPPType> CPPTYPE_##IDENTIFIER = create_cpp_type<TYPE_NAME>( \
- STRINGIFY(IDENTIFIER), BLI_RAND_PER_LINE_UINT32); \
+ STRINGIFY(IDENTIFIER), BLI_RAND_PER_LINE_UINT32, default_value_##IDENTIFIER); \
template<> const CPPType &CPP_TYPE<TYPE_NAME>() \
{ \
return *CPPTYPE_##IDENTIFIER; \