diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2014-04-16 10:48:27 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2014-04-16 10:48:27 +0000 |
commit | d66a3fe1064313da76aa39cda8bf0481d5f101a8 (patch) | |
tree | d63f11bb8b921ce5d6ba34371665375f556c3e6c /include/llvm/Support/Allocator.h | |
parent | b78eac2d4d614010dc75f58371ca444bd7dbc6af (diff) | |
download | llvm-d66a3fe1064313da76aa39cda8bf0481d5f101a8.tar.gz llvm-d66a3fe1064313da76aa39cda8bf0481d5f101a8.tar.bz2 llvm-d66a3fe1064313da76aa39cda8bf0481d5f101a8.tar.xz |
[Allocator] Make BumpPtrAllocator movable and move assignable.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206372 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/Allocator.h')
-rw-r--r-- | include/llvm/Support/Allocator.h | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/include/llvm/Support/Allocator.h b/include/llvm/Support/Allocator.h index a2923fdd69..cc3675c938 100644 --- a/include/llvm/Support/Allocator.h +++ b/include/llvm/Support/Allocator.h @@ -138,9 +138,6 @@ template <typename AllocatorT = MallocAllocator, size_t SlabSize = 4096, class BumpPtrAllocatorImpl : public AllocatorBase< BumpPtrAllocatorImpl<AllocatorT, SlabSize, SizeThreshold>> { - BumpPtrAllocatorImpl(const BumpPtrAllocatorImpl &) LLVM_DELETED_FUNCTION; - void operator=(const BumpPtrAllocatorImpl &) LLVM_DELETED_FUNCTION; - public: static_assert(SizeThreshold <= SlabSize, "The SizeThreshold must be at most the SlabSize to ensure " @@ -153,11 +150,43 @@ public: BumpPtrAllocatorImpl(T &&Allocator) : CurPtr(nullptr), End(nullptr), BytesAllocated(0), Allocator(std::forward<T &&>(Allocator)) {} + + // Manually implement a move constructor as we must clear the old allocators + // slabs as a matter of correctness. + BumpPtrAllocatorImpl(BumpPtrAllocatorImpl &&Old) + : CurPtr(Old.CurPtr), End(Old.End), Slabs(std::move(Old.Slabs)), + CustomSizedSlabs(std::move(Old.CustomSizedSlabs)), + BytesAllocated(Old.BytesAllocated), + Allocator(std::move(Old.Allocator)) { + Old.CurPtr = Old.End = nullptr; + Old.BytesAllocated = 0; + Old.Slabs.clear(); + Old.CustomSizedSlabs.clear(); + } + ~BumpPtrAllocatorImpl() { DeallocateSlabs(Slabs.begin(), Slabs.end()); DeallocateCustomSizedSlabs(); } + BumpPtrAllocatorImpl &operator=(BumpPtrAllocatorImpl &&RHS) { + DeallocateSlabs(Slabs.begin(), Slabs.end()); + DeallocateCustomSizedSlabs(); + + CurPtr = RHS.CurPtr; + End = RHS.End; + BytesAllocated = RHS.BytesAllocated; + Slabs = std::move(RHS.Slabs); + CustomSizedSlabs = std::move(RHS.CustomSizedSlabs); + Allocator = std::move(RHS.Allocator); + + RHS.CurPtr = RHS.End = nullptr; + RHS.BytesAllocated = 0; + RHS.Slabs.clear(); + RHS.CustomSizedSlabs.clear(); + return *this; + } + /// \brief Deallocate all but the current slab and reset the current pointer /// to the beginning of it, freeing all memory allocated so far. void Reset() { |