aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/util/Memory.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2011-06-09 19:04:06 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2011-06-09 19:04:06 +0200
commit6d3dee1b66ce77b82f2d4e1c052f78c8c9ccdc5d (patch)
treeae557fdcdce03291feb0afd4bbb8608ddb444a79 /Eigen/src/Core/util/Memory.h
parent8c8ab9ae103930e21da76ed6dcbaa585e8af7ff4 (diff)
introduce a smart_copy internal function and fix sparse matrices with non POD scalar type
Diffstat (limited to 'Eigen/src/Core/util/Memory.h')
-rw-r--r--Eigen/src/Core/util/Memory.h23
1 files changed, 22 insertions, 1 deletions
diff --git a/Eigen/src/Core/util/Memory.h b/Eigen/src/Core/util/Memory.h
index 8e4eccd95..f9bafab57 100644
--- a/Eigen/src/Core/util/Memory.h
+++ b/Eigen/src/Core/util/Memory.h
@@ -462,6 +462,27 @@ inline static Index first_aligned(const Scalar* array, Index size)
}
}
+
+// std::copy is much slower than std::copy, so let's introduce a smart_copy which
+// use memcpy on trivial types, i.e., on types that does not require an initialization ctor.
+template<typename T, bool UseMemcpy> struct smart_copy_helper;
+
+template<typename T> void smart_copy(const T* start, const T* end, T* target)
+{
+ smart_copy_helper<T,!NumTraits<T>::RequireInitialization>::run(start, end, target);
+}
+
+template<typename T> struct smart_copy_helper<T,true> {
+ inline static void run(const T* start, const T* end, T* target)
+ { memcpy(target, start, std::ptrdiff_t(end)-std::ptrdiff_t(start)); }
+};
+
+template<typename T> struct smart_copy_helper<T,false> {
+ inline static void run(const T* start, const T* end, T* target)
+ { std::copy(start, end, target); }
+};
+
+
} // end namespace internal
/*****************************************************************************
@@ -517,7 +538,7 @@ template<typename T> class aligned_stack_memory_handler
* if SIZE is smaller than EIGEN_STACK_ALLOCATION_LIMIT, and if stack allocation is supported by the platform
* (currently, this is Linux and Visual Studio only). Otherwise the memory is allocated on the heap.
* The allocated buffer is automatically deleted when exiting the scope of this declaration.
- * If BUFFER is non nul, then the declared variable is simply an alias for BUFFER, and no allocation/deletion occurs.
+ * If BUFFER is non null, then the declared variable is simply an alias for BUFFER, and no allocation/deletion occurs.
* Here is an example:
* \code
* {