aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src
diff options
context:
space:
mode:
authorGravatar Pavel Holoborodko <pavel@holoborodko.com>2013-08-25 18:00:28 +0900
committerGravatar Pavel Holoborodko <pavel@holoborodko.com>2013-08-25 18:00:28 +0900
commita147500dee85092fbfbf755123553f412a218ec2 (patch)
tree7d77544178b8ce3dc7369f3bc40303d769bd2f4c /Eigen/src
parentd1c48f16061a60d92ab6f4df1e877f20c17d78d0 (diff)
Added smart_memmove with support of non-POD scalars (e.g. needed in SparseBlock.h).
Diffstat (limited to 'Eigen/src')
-rw-r--r--Eigen/src/Core/util/Memory.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/Eigen/src/Core/util/Memory.h b/Eigen/src/Core/util/Memory.h
index 451535a0c..3a357e079 100644
--- a/Eigen/src/Core/util/Memory.h
+++ b/Eigen/src/Core/util/Memory.h
@@ -6,6 +6,7 @@
// Copyright (C) 2009 Kenneth Riddile <kfriddile@yahoo.com>
// Copyright (C) 2010 Hauke Heibel <hauke.heibel@gmail.com>
// Copyright (C) 2010 Thomas Capricelli <orzel@freehackers.org>
+// Copyright (C) 2013 Pavel Holoborodko <pavel@holoborodko.com>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
@@ -514,6 +515,34 @@ template<typename T> struct smart_copy_helper<T,false> {
{ std::copy(start, end, target); }
};
+// intelligent memmove. falls back to std::memmove for POD types, uses std::copy otherwise.
+template<typename T, bool UseMemmove> struct smart_memmove_helper;
+
+template<typename T> void smart_memmove(const T* start, const T* end, T* target)
+{
+ smart_memmove_helper<T,!NumTraits<T>::RequireInitialization>::run(start, end, target);
+}
+
+template<typename T> struct smart_memmove_helper<T,true> {
+ static inline void run(const T* start, const T* end, T* target)
+ { std::memmove(target, start, std::ptrdiff_t(end)-std::ptrdiff_t(start)); }
+};
+
+template<typename T> struct smart_memmove_helper<T,false> {
+ static inline void run(const T* start, const T* end, T* target)
+ {
+ if (uintptr_t(target) < uintptr_t(start))
+ {
+ std::copy(start, end, target);
+ }
+ else
+ {
+ std::ptrdiff_t count = (std::ptrdiff_t(end)-std::ptrdiff_t(start)) / sizeof(T);
+ std::copy_backward(start, end, target + count);
+ }
+ }
+};
+
/*****************************************************************************
*** Implementation of runtime stack allocation (falling back to malloc) ***