[Bf-blender-cvs] [74e40a88631] functions: Tuple::copy_element
Jacques Lucke
noreply at git.blender.org
Sun Feb 10 20:26:01 CET 2019
Commit: 74e40a886311113ca9d223c7ccf702cae7a66b96
Author: Jacques Lucke
Date: Mon Feb 4 16:42:06 2019 +0100
Branches: functions
https://developer.blender.org/rB74e40a886311113ca9d223c7ccf702cae7a66b96
Tuple::copy_element
===================================================================
M source/blender/functions/core/cpu.hpp
===================================================================
diff --git a/source/blender/functions/core/cpu.hpp b/source/blender/functions/core/cpu.hpp
index 1bf65982e91..33ca9a4a144 100644
--- a/source/blender/functions/core/cpu.hpp
+++ b/source/blender/functions/core/cpu.hpp
@@ -67,12 +67,12 @@ namespace FN {
BLI_assert(sizeof(T) == this->element_size(index));
if (std::is_trivial<T>::value) {
- std::memcpy((char *)this->data + this->m_offsets[index], &value, sizeof(T));
+ std::memcpy(this->element_ptr(index), &value, sizeof(T));
}
else {
const T *begin = &value;
const T *end = begin + 1;
- T *dst = (T *)((char *)this->data + this->m_offsets[index]);
+ T *dst = (T *)this->element_ptr(index);
if (this->m_initialized[index]) {
std::copy(begin, end, dst);
@@ -94,7 +94,17 @@ namespace FN {
BLI_assert(this->m_initialized[index]);
}
- return *(T *)((char *)this->data + this->m_offsets[index]);;
+ return *(T *)this->element_ptr(index);
+ }
+
+ static inline void copy_element(
+ const Tuple &from, uint from_index,
+ Tuple &to, uint to_index)
+ {
+ /* only works with trivially copyable data types for now */
+ BLI_assert(from.m_types[from_index] == to.m_types[to_index]);
+ uint size = from.element_size(from_index);
+ memcpy(to.element_ptr(to_index), from.element_ptr(from_index), size);
}
private:
@@ -103,6 +113,11 @@ namespace FN {
return this->m_offsets[index + 1] - this->m_offsets[index];
}
+ inline void *element_ptr(uint index) const
+ {
+ return (void *)((char *)this->data + this->m_offsets[index]);
+ }
+
const SmallTypeVector m_types;
SmallVector<uint> m_offsets;
SmallVector<bool> m_initialized;
More information about the Bf-blender-cvs
mailing list