From 2676f183123e1472c8d9d7f6a64f1d50a74e484a Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 16 Dec 2009 08:09:23 +0000 Subject: [PATCH] pull destroy_range and uninitialized_copy up to the SmallVectorTemplateBase class, which allows us to statically dispatch on isPodLike instead of dynamically. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91523 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/SmallVector.h | 58 +++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h index b166ab49323..55634a02dbd 100644 --- a/include/llvm/ADT/SmallVector.h +++ b/include/llvm/ADT/SmallVector.h @@ -157,19 +157,47 @@ public: } }; - +/// SmallVectorTemplateBase - This is where we put method +/// implementations that are designed to work with non-POD-like T's. template class SmallVectorTemplateBase : public SmallVectorTemplateCommon { public: SmallVectorTemplateBase(size_t Size) : SmallVectorTemplateCommon(Size) {} + static void destroy_range(T *S, T *E) { + while (S != E) { + --E; + E->~T(); + } + } + + /// uninitialized_copy - Copy the range [I, E) onto the uninitialized memory + /// starting with "Dest", constructing elements into it as needed. + template + static void uninitialized_copy(It1 I, It1 E, It2 Dest) { + std::uninitialized_copy(I, E, Dest); + } + }; +/// SmallVectorTemplateBase - This is where we put method +/// implementations that are designed to work with POD-like T's. template class SmallVectorTemplateBase : public SmallVectorTemplateCommon { public: SmallVectorTemplateBase(size_t Size) : SmallVectorTemplateCommon(Size) {} + // No need to do a destroy loop for POD's. + static void destroy_range(T *S, T *E) {} + + /// uninitialized_copy - Copy the range [I, E) onto the uninitialized memory + /// starting with "Dest", constructing elements into it as needed. + template + static void uninitialized_copy(It1 I, It1 E, It2 Dest) { + // Use memcpy for PODs: std::uninitialized_copy optimizes to memmove, memcpy + // is better. + memcpy(&*Dest, &*I, (E-I)*sizeof(T)); + } }; @@ -178,11 +206,10 @@ public: /// template parameter. template class SmallVectorImpl : public SmallVectorTemplateBase::value> { + typedef SmallVectorTemplateBase::value > SuperClass; public: - typedef typename SmallVectorTemplateBase::value >::iterator - iterator; - typedef typename SmallVectorTemplateBase::value >::size_type - size_type; + typedef typename SuperClass::iterator iterator; + typedef typename SuperClass::size_type size_type; // Default ctor - Initialize to empty. explicit SmallVectorImpl(unsigned N) @@ -469,27 +496,6 @@ private: for (; S != E; ++S) new (S) T(Elt); } - - static void destroy_range(T *S, T *E) { - // No need to do a destroy loop for POD's. - if (isPodLike::value) return; - - while (S != E) { - --E; - E->~T(); - } - } - - /// uninitialized_copy - Copy the range [I, E) onto the uninitialized memory - /// starting with "Dest", constructing elements into it as needed. - template - static void uninitialized_copy(It1 I, It1 E, It2 Dest) { - // Use memcpy for PODs: std::uninitialized_copy optimizes to memmove. - if (isPodLike::value) - memcpy(&*Dest, &*I, (E-I)*sizeof(T)); - else - std::uninitialized_copy(I, E, Dest); - } };