From 3fa8c4b046b4b7bf5bf702ac2bbc54c97d326bdd Mon Sep 17 00:00:00 2001 From: Seth Fowler Date: Wed, 10 Sep 2014 17:06:37 -0700 Subject: [PATCH] Bug 1057894 (Part 1) - Make VolatileBufferPtr's moveable. r=mwu --- memory/mozalloc/VolatileBuffer.h | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/memory/mozalloc/VolatileBuffer.h b/memory/mozalloc/VolatileBuffer.h index 89e875156efc..0f8a1e6dd13e 100644 --- a/memory/mozalloc/VolatileBuffer.h +++ b/memory/mozalloc/VolatileBuffer.h @@ -91,6 +91,7 @@ public: } protected: + RefPtr mVBuf; void* mMapping; void Set(VolatileBuffer* vbuf) { @@ -100,7 +101,6 @@ protected: } private: - RefPtr mVBuf; bool mPurged; void Lock() { @@ -126,13 +126,30 @@ public: explicit VolatileBufferPtr(VolatileBuffer* vbuf) : VolatileBufferPtr_base(vbuf) {} VolatileBufferPtr() : VolatileBufferPtr_base(nullptr) {} + VolatileBufferPtr(VolatileBufferPtr&& aOther) + : VolatileBufferPtr_base(aOther.mVBuf) + { + aOther.Set(nullptr); + } + operator T*() const { return (T*) mMapping; } - void operator =(VolatileBuffer* vbuf) { - Set(vbuf); + VolatileBufferPtr& operator=(VolatileBuffer* aVBuf) + { + Set(aVBuf); + return *this; } + + VolatileBufferPtr& operator=(VolatileBufferPtr&& aOther) + { + MOZ_ASSERT(this != &aOther, "Self-moves are prohibited"); + Set(aOther.mVBuf); + aOther.Set(nullptr); + return *this; + } + private: VolatileBufferPtr(VolatileBufferPtr const& vbufptr) MOZ_DELETE; };