Fix layering StringRef copy using BumpPtrAllocator.
[oota-llvm.git] / include / llvm / ADT / ArrayRef.h
index e5562c368309836ab9889c0c755ef3f7dc1d8346..c95889a18745d5e78609cfcf735f1a2facdad729 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Allocator.h"
 #include <vector>
 
 namespace llvm {
@@ -120,6 +121,13 @@ namespace llvm {
       return Data[Length-1];
     }
 
+    // copy - Allocate copy in BumpPtrAllocator and return ArrayRef<T> to it.
+    ArrayRef<T> copy(BumpPtrAllocator &Allocator) {
+      T *Buff = Allocator.Allocate<T>(Length);
+      std::copy(begin(), end(), Buff);
+      return ArrayRef<T>(Buff, Length);
+    }
+
     /// equals - Check for element-wise equality.
     bool equals(ArrayRef RHS) const {
       if (Length != RHS.Length)