[ADT] Have ArrayRef::copy() return a MutableArrayRef
authorJez Ng <jezng@fb.com>
Fri, 18 Feb 2022 19:56:16 +0000 (14:56 -0500)
committerJez Ng <jezng@fb.com>
Fri, 18 Feb 2022 19:56:16 +0000 (14:56 -0500)
The allocated memory itself is mutable, so let's expose that to the
caller. LLD has a use case for this.

Reviewed By: MaskRay, #lld-macho

Differential Revision: https://reviews.llvm.org/D120144

llvm/include/llvm/ADT/ArrayRef.h

index b689639..9af4232 100644 (file)
@@ -25,6 +25,7 @@
 #include <vector>
 
 namespace llvm {
+  template<typename T> class LLVM_NODISCARD MutableArrayRef;
 
   /// ArrayRef - Represent a constant reference to an array (0 or more elements
   /// consecutively in memory), i.e. a start pointer and a length.  It allows
@@ -175,10 +176,10 @@ namespace llvm {
     }
 
     // copy - Allocate copy in Allocator and return ArrayRef<T> to it.
-    template <typename Allocator> ArrayRef<T> copy(Allocator &A) {
+    template <typename Allocator> MutableArrayRef<T> copy(Allocator &A) {
       T *Buff = A.template Allocate<T>(Length);
       std::uninitialized_copy(begin(), end(), Buff);
-      return ArrayRef<T>(Buff, Length);
+      return MutableArrayRef<T>(Buff, Length);
     }
 
     /// equals - Check for element-wise equality.