Fix layering StringRef copy using BumpPtrAllocator.
[oota-llvm.git] / include / llvm / ADT / StringRef.h
index 2128f37dd3d0aabab935727b5485bc437ef84cfb..a1d10c18d78cafe1217b1c10eef13a66eaa75c76 100644 (file)
@@ -11,6 +11,7 @@
 #define LLVM_ADT_STRINGREF_H
 
 #include "llvm/Support/type_traits.h"
+#include "llvm/Support/Allocator.h"
 #include <algorithm>
 #include <cassert>
 #include <cstring>
@@ -124,6 +125,13 @@ namespace llvm {
       return Data[Length-1];
     }
 
+    // copy - Allocate copy in BumpPtrAllocator and return StringRef to it.
+    StringRef copy(BumpPtrAllocator &Allocator) {
+      char *S = Allocator.Allocate<char>(Length);
+      std::copy(begin(), end(), S);
+      return StringRef(S, Length);
+    }
+
     /// equals - Check for string equality, this is more efficient than
     /// compare() when the relative ordering of inequal strings isn't needed.
     bool equals(StringRef RHS) const {