[llvm] r289579 - ADT: Add OwningArrayRef class.
John McCall via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 19 21:42:50 PST 2016
> On Dec 19, 2016, at 8:29 PM, David Blaikie <dblaikie at gmail.com> wrote:
> What I mean is: compare OwningArrayRef to std::vector, not OwningArrayRef to manual memory management
std::vector does have some storage overhead from the need to be resized, whereas this is clearly just for storing pre-computed arrays. Seems reasonable to me.
John.
>
> On Mon, Dec 19, 2016 at 8:07 PM Peter Collingbourne <peter at pcc.me.uk <mailto:peter at pcc.me.uk>> wrote:
> I don't really have a strong opinion about it. It wraps up some manual memory management code we used to have in the vtable builder, although I couldn't say how beneficial that memory management really is.
>
> Peter
>
> On Mon, Dec 19, 2016 at 7:56 PM, David Blaikie <dblaikie at gmail.com <mailto:dblaikie at gmail.com>> wrote:
> Is this really worth having compared to std::vector? std::dynarray was rejected from standardization for that reason, if I understand/heard correctly (& OwningArrayRef seems similar to std::dynarray)
>
> On Tue, Dec 13, 2016 at 12:34 PM Peter Collingbourne via llvm-commits <llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>> wrote:
> Author: pcc
> Date: Tue Dec 13 14:24:24 2016
> New Revision: 289579
>
> URL: http://llvm.org/viewvc/llvm-project?rev=289579&view=rev <http://llvm.org/viewvc/llvm-project?rev=289579&view=rev>
> Log:
> ADT: Add OwningArrayRef class.
>
> This is a MutableArrayRef that owns its array.
> I plan to use this in D22296.
>
> Differential Revision: https://reviews.llvm.org/D27723 <https://reviews.llvm.org/D27723>
>
> Modified:
> llvm/trunk/include/llvm/ADT/ArrayRef.h
>
> Modified: llvm/trunk/include/llvm/ADT/ArrayRef.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ArrayRef.h?rev=289579&r1=289578&r2=289579&view=diff <http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ArrayRef.h?rev=289579&r1=289578&r2=289579&view=diff>
> ==============================================================================
> --- llvm/trunk/include/llvm/ADT/ArrayRef.h (original)
> +++ llvm/trunk/include/llvm/ADT/ArrayRef.h Tue Dec 13 14:24:24 2016
> @@ -413,6 +413,25 @@ namespace llvm {
> }
> };
>
> + /// This is a MutableArrayRef that owns its array.
> + template <typename T> class OwningArrayRef : public MutableArrayRef<T> {
> + public:
> + OwningArrayRef() {}
> + OwningArrayRef(size_t Size) : MutableArrayRef<T>(new T[Size], Size) {}
> + OwningArrayRef(ArrayRef<T> Data)
> + : MutableArrayRef<T>(new T[Data.size()], Data.size()) {
> + std::copy(Data.begin(), Data.end(), this->begin());
> + }
> + OwningArrayRef(OwningArrayRef &&Other) { *this = Other; }
> + OwningArrayRef &operator=(OwningArrayRef &&Other) {
> + delete this->data();
> + this->MutableArrayRef<T>::operator=(Other);
> + Other.MutableArrayRef<T>::operator=(MutableArrayRef<T>());
> + return *this;
> + }
> + ~OwningArrayRef() { delete this->data(); }
> + };
> +
> /// @name ArrayRef Convenience constructors
> /// @{
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits>
>
>
>
> --
> --
> Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161219/88737b83/attachment.html>
More information about the llvm-commits
mailing list