diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-12-16 08:09:23 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-12-16 08:09:23 +0000 |
| commit | f684b9039d2069a9baf11d6045e54c0b1ca1df11 (patch) | |
| tree | fb916f8dd5cf767cf7a1399ea9c6432e9273c452 /llvm/include | |
| parent | acc0e62625c29ba8014005dac5b41d8c3a50ad2c (diff) | |
| download | bcm5719-llvm-f684b9039d2069a9baf11d6045e54c0b1ca1df11.tar.gz bcm5719-llvm-f684b9039d2069a9baf11d6045e54c0b1ca1df11.zip | |
pull destroy_range and uninitialized_copy up to the
SmallVectorTemplateBase class, which allows us to statically
dispatch on isPodLike instead of dynamically.
llvm-svn: 91523
Diffstat (limited to 'llvm/include')
| -rw-r--r-- | llvm/include/llvm/ADT/SmallVector.h | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h index b166ab49323..55634a02dbd 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -157,19 +157,47 @@ public: } }; - +/// SmallVectorTemplateBase<isPodLike = false> - This is where we put method +/// implementations that are designed to work with non-POD-like T's. template <typename T, bool isPodLike> class SmallVectorTemplateBase : public SmallVectorTemplateCommon<T> { public: SmallVectorTemplateBase(size_t Size) : SmallVectorTemplateCommon<T>(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<typename It1, typename It2> + static void uninitialized_copy(It1 I, It1 E, It2 Dest) { + std::uninitialized_copy(I, E, Dest); + } + }; +/// SmallVectorTemplateBase<isPodLike = true> - This is where we put method +/// implementations that are designed to work with POD-like T's. template <typename T> class SmallVectorTemplateBase<T, true> : public SmallVectorTemplateCommon<T> { public: SmallVectorTemplateBase(size_t Size) : SmallVectorTemplateCommon<T>(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<typename It1, typename It2> + 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 <typename T> class SmallVectorImpl : public SmallVectorTemplateBase<T, isPodLike<T>::value> { + typedef SmallVectorTemplateBase<T, isPodLike<T>::value > SuperClass; public: - typedef typename SmallVectorTemplateBase<T, isPodLike<T>::value >::iterator - iterator; - typedef typename SmallVectorTemplateBase<T, isPodLike<T>::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<T>::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<typename It1, typename It2> - static void uninitialized_copy(It1 I, It1 E, It2 Dest) { - // Use memcpy for PODs: std::uninitialized_copy optimizes to memmove. - if (isPodLike<T>::value) - memcpy(&*Dest, &*I, (E-I)*sizeof(T)); - else - std::uninitialized_copy(I, E, Dest); - } }; |

