Added ImmutableMap constructor that accepts a const TreeTy*.
[oota-llvm.git] / include / llvm / ADT / SmallVector.h
index 2da6a788ebac9a26a5e04bbda0ecfe649d5e9733..d98d40a3f391c81a9ea4613debd3acb8cc133f87 100644 (file)
 #ifndef LLVM_ADT_SMALLVECTOR_H
 #define LLVM_ADT_SMALLVECTOR_H
 
-#include "llvm/ADT/iterator"
+#include "llvm/ADT/iterator.h"
+#include "llvm/Support/type_traits.h"
 #include <algorithm>
+#include <cstring>
 #include <memory>
 
 #ifdef _MSC_VER
@@ -84,7 +86,7 @@ public:
 
     // If this wasn't grown from the inline copy, deallocate the old space.
     if (!isSmall())
-      delete[] reinterpret_cast<char*>(Begin);
+      operator delete(Begin);
   }
   
   typedef size_t size_type;
@@ -300,20 +302,25 @@ public:
   
   bool operator==(const SmallVectorImpl &RHS) const {
     if (size() != RHS.size()) return false;
-    for (T *This = Begin, *That = RHS.Begin, *End = Begin+size(); 
-         This != End; ++This, ++That)
+    for (T *This = Begin, *That = RHS.Begin, *E = Begin+size(); 
+         This != E; ++This, ++That)
       if (*This != *That)
         return false;
     return true;
   }
   bool operator!=(const SmallVectorImpl &RHS) const { return !(*this == RHS); }
+
+  bool operator<(const SmallVectorImpl &RHS) const {
+    return std::lexicographical_compare(begin(), end(),
+                                        RHS.begin(), RHS.end());
+  }
   
 private:
   /// isSmall - Return true if this is a smallvector which has not had dynamic
   /// memory allocated for it.
   bool isSmall() const {
-    return reinterpret_cast<const void*>(Begin) == 
-           reinterpret_cast<const void*>(&FirstEl);
+    return static_cast<const void*>(Begin) == 
+           static_cast<const void*>(&FirstEl);
   }
 
   /// grow - double the size of the allocated memory, guaranteeing space for at
@@ -341,17 +348,21 @@ void SmallVectorImpl<T>::grow(size_t MinSize) {
   size_t NewCapacity = 2*CurCapacity;
   if (NewCapacity < MinSize)
     NewCapacity = MinSize;
-  T *NewElts = reinterpret_cast<T*>(new char[NewCapacity*sizeof(T)]);
+  T *NewElts = static_cast<T*>(operator new(NewCapacity*sizeof(T)));
   
   // Copy the elements over.
-  std::uninitialized_copy(Begin, End, NewElts);
+  if (is_class<T>::value)
+    std::uninitialized_copy(Begin, End, NewElts);
+  else
+    // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
+    memcpy(NewElts, Begin, CurSize * sizeof(T));
   
   // Destroy the original elements.
   destroy_range(Begin, End);
   
   // If this wasn't grown from the inline copy, deallocate the old space.
   if (!isSmall())
-    delete[] reinterpret_cast<char*>(Begin);
+    operator delete(Begin);
   
   Begin = NewElts;
   End = NewElts+CurSize;