pull destroy_range and uninitialized_copy up to the
authorChris Lattner <sabre@nondot.org>
Wed, 16 Dec 2009 08:09:23 +0000 (08:09 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 16 Dec 2009 08:09:23 +0000 (08:09 +0000)
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

index b166ab49323a88594457a796c0617b0ea02a7264..55634a02dbdf6df630ee5d1261487057ca340177 100644 (file)
@@ -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);
-  }
 };