From: Benjamin Kramer Date: Fri, 13 Feb 2015 20:45:14 +0000 (+0000) Subject: Reapply r229142 with some enable_if magic to avoid memcpying between differing types. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f7803d51f4d147fc2af20e8b2451c0479495dd5c;p=oota-llvm.git 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229149 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h index af9bbb62345..086f8454daf 100644 --- a/include/llvm/ADT/SmallVector.h +++ b/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 - static void uninitialized_copy(T1 *I, T1 *E, T2 *Dest) { + template + static void uninitialized_copy( + T1 *I, T1 *E, T2 *Dest, + typename std::enable_if::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); }