summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2015-02-13 20:45:14 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2015-02-13 20:45:14 +0000
commitbad5a46c05b290b64f764ba4a4eaedc6c8699f25 (patch)
treecf8896b3e0c15e480494bfea6668b3582f25caa0
parent14a92711ce08158e8e05295b065ed389e679193f (diff)
downloadbcm5719-llvm-bad5a46c05b290b64f764ba4a4eaedc6c8699f25.tar.gz
bcm5719-llvm-bad5a46c05b290b64f764ba4a4eaedc6c8699f25.zip
Reapply r229142 with some enable_if magic to avoid memcpying between differing types.
Original commit message: SmallVector: Resolve a long-standing fixme by using the existing unitialized_copy dispatch. This makes append() use memcpy for trivially copyable types. llvm-svn: 229149
-rw-r--r--llvm/include/llvm/ADT/SmallVector.h11
1 files changed, 6 insertions, 5 deletions
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index af9bbb62345..086f8454daf 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -307,8 +307,11 @@ protected:
/// Copy the range [I, E) onto the uninitialized memory
/// starting with "Dest", constructing elements into it as needed.
- template<typename T1, typename T2>
- static void uninitialized_copy(T1 *I, T1 *E, T2 *Dest) {
+ template <typename T1, typename T2>
+ static void uninitialized_copy(
+ T1 *I, T1 *E, T2 *Dest,
+ typename std::enable_if<std::is_same<typename std::remove_const<T1>::type,
+ T2>::value>::type * = nullptr) {
// Use memcpy for PODs iterated by pointers (which includes SmallVector
// iterators): std::uninitialized_copy optimizes to memmove, but we can
// use memcpy here.
@@ -414,9 +417,7 @@ public:
this->grow(this->size()+NumInputs);
// Copy the new elements over.
- // TODO: NEED To compile time dispatch on whether in_iter is a random access
- // iterator to use the fast uninitialized_copy.
- std::uninitialized_copy(in_start, in_end, this->end());
+ this->uninitialized_copy(in_start, in_end, this->end());
this->setEnd(this->end() + NumInputs);
}
OpenPOWER on IntegriCloud