[llvm-commits] [llvm] r91523 - /llvm/trunk/include/llvm/ADT/SmallVector.h

Chris Lattner sabre at nondot.org
Wed Dec 16 00:09:23 PST 2009


Author: lattner
Date: Wed Dec 16 02:09:23 2009
New Revision: 91523

URL: http://llvm.org/viewvc/llvm-project?rev=91523&view=rev
Log:
pull destroy_range and uninitialized_copy up to the
SmallVectorTemplateBase class, which allows us to statically
dispatch on isPodLike instead of dynamically.

Modified:
    llvm/trunk/include/llvm/ADT/SmallVector.h

Modified: llvm/trunk/include/llvm/ADT/SmallVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=91523&r1=91522&r2=91523&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallVector.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallVector.h Wed Dec 16 02:09:23 2009
@@ -157,19 +157,47 @@
   }
 };
   
-  
+/// 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 @@
 /// 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 @@
     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);
-  }
 };
   
 





More information about the llvm-commits mailing list