From 0712c575b90a7eb508bf43d15c38c1c0b0d69695 Mon Sep 17 00:00:00 2001 From: Jez Ng Date: Fri, 18 Feb 2022 14:56:16 -0500 Subject: [PATCH] [ADT] Have ArrayRef::copy() return a MutableArrayRef 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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h index b689639..9af4232 100644 --- a/llvm/include/llvm/ADT/ArrayRef.h +++ b/llvm/include/llvm/ADT/ArrayRef.h @@ -25,6 +25,7 @@ #include namespace llvm { + template 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 to it. - template ArrayRef copy(Allocator &A) { + template MutableArrayRef copy(Allocator &A) { T *Buff = A.template Allocate(Length); std::uninitialized_copy(begin(), end(), Buff); - return ArrayRef(Buff, Length); + return MutableArrayRef(Buff, Length); } /// equals - Check for element-wise equality. -- 2.7.4