a few improvements:
authorChris Lattner <sabre@nondot.org>
Tue, 15 Dec 2009 08:34:01 +0000 (08:34 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 15 Dec 2009 08:34:01 +0000 (08:34 +0000)
1. Use std::equal instead of reinventing it.
2. don't run dtors in destroy_range if element is pod-like.
3. Use isPodLike to decide between memcpy/uninitialized_copy
   instead of is_class.  isPodLike is more generous in some cases.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91427 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/SmallVector.h

index 69c25d0d962f9dcc51b0ee74d35d40145e0b3e0b..b16649e23c993234b28cf506d1ab66f3dbf54482 100644 (file)
@@ -402,11 +402,7 @@ public:
 
   bool operator==(const SmallVectorImpl &RHS) const {
     if (size() != RHS.size()) return false;
-    for (const T *This = begin(), *That = RHS.begin(), *E = end();
-         This != E; ++This, ++That)
-      if (*This != *That)
-        return false;
-    return true;
+    return std::equal(begin(), end(), RHS.begin());
   }
   bool operator!=(const SmallVectorImpl &RHS) const { return !(*this == RHS); }
 
@@ -440,7 +436,9 @@ private:
   }
 
   void destroy_range(T *S, T *E) {
-    // TODO: POD
+    // No need to do a destroy loop for POD's.
+    if (isPodLike<T>::value) return;
+    
     while (S != E) {
       --E;
       E->~T();
@@ -459,11 +457,11 @@ void SmallVectorImpl<T>::grow(size_t MinSize) {
   T *NewElts = static_cast<T*>(operator new(NewCapacity*sizeof(T)));
 
   // Copy the elements over.
-  if (is_class<T>::value)
-    std::uninitialized_copy(begin(), end(), NewElts);
-  else
-    // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
+  if (isPodLike<T>::value)
+    // Use memcpy for PODs: std::uninitialized_copy optimizes to memmove.
     memcpy(NewElts, begin(), CurSize * sizeof(T));
+  else
+    std::uninitialized_copy(begin(), end(), NewElts);
 
   // Destroy the original elements.
   destroy_range(begin(), end());