Bug 1049957 - Use custom std::queue wrapper instead of std::queue<UniquePtr<T>>. - r=kamidphish

This commit is contained in:
Jeff Gilbert 2014-08-15 17:38:08 -07:00
parent 7e8c7b365e
commit 794ccee7a4
4 changed files with 44 additions and 16 deletions

View File

@ -268,9 +268,8 @@ SurfaceFactory::SurfaceFactory(GLContext* gl,
SurfaceFactory::~SurfaceFactory()
{
while (!mScraps.empty()) {
UniquePtr<SharedSurface> cur = Move(mScraps.front());
mScraps.pop();
while (!mScraps.Empty()) {
UniquePtr<SharedSurface> cur = mScraps.Pop();
}
}
@ -278,9 +277,8 @@ UniquePtr<SharedSurface>
SurfaceFactory::NewSharedSurface(const gfx::IntSize& size)
{
// Attempt to reuse an old surface.
while (!mScraps.empty()) {
UniquePtr<SharedSurface> cur = Move(mScraps.front());
mScraps.pop();
while (!mScraps.Empty()) {
UniquePtr<SharedSurface> cur = mScraps.Pop();
if (cur->mSize == size)
return Move(cur);
@ -299,7 +297,7 @@ SurfaceFactory::Recycle(UniquePtr<SharedSurface> surf)
MOZ_ASSERT(surf);
if (surf->mType == mType) {
mScraps.push(Move(surf));
mScraps.Push(Move(surf));
}
}

View File

@ -114,6 +114,38 @@ public:
}
};
template<typename T>
class UniquePtrQueue
{
std::queue<T*> mQueue;
public:
~UniquePtrQueue() {
MOZ_ASSERT(Empty());
}
bool Empty() const {
return mQueue.empty();
}
void Push(UniquePtr<T> up) {
T* p = up.release();
mQueue.push(p);
}
UniquePtr<T> Pop() {
UniquePtr<T> ret;
if (mQueue.empty())
return Move(ret);
T* p = mQueue.front();
mQueue.pop();
ret.reset(p);
return Move(ret);
}
};
class SurfaceFactory
{
public:
@ -144,7 +176,7 @@ public:
protected:
virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) = 0;
std::queue< UniquePtr<SharedSurface> > mScraps;
UniquePtrQueue<SharedSurface> mScraps;
public:
UniquePtr<SharedSurface> NewSharedSurface(const gfx::IntSize& size);

View File

@ -185,7 +185,7 @@ SurfaceStream::Scrap(UniquePtr<SharedSurface>* surfSlot)
UniquePtr<SharedSurface>& surf = *surfSlot;
if (surf) {
mScraps.push(Move(surf));
mScraps.Push(Move(surf));
surf = nullptr;
}
MOZ_ASSERT(!surf);
@ -195,9 +195,8 @@ SurfaceStream::Scrap(UniquePtr<SharedSurface>* surfSlot)
void
SurfaceStream::RecycleScraps(SurfaceFactory* factory)
{
while (!mScraps.empty()) {
UniquePtr<SharedSurface> cur = Move(mScraps.top());
mScraps.pop();
while (!mScraps.Empty()) {
UniquePtr<SharedSurface> cur = mScraps.Pop();
Recycle(factory, &cur);
}
@ -222,9 +221,8 @@ SurfaceStream::~SurfaceStream()
{
Delete(&mProducer);
while (!mScraps.empty()) {
UniquePtr<SharedSurface> cur = Move(mScraps.top());
mScraps.pop();
while (!mScraps.Empty()) {
UniquePtr<SharedSurface> cur = mScraps.Pop();
Delete(&cur);
}

View File

@ -52,7 +52,7 @@ protected:
#ifdef DEBUG
std::set<SharedSurface*> mSurfaces;
#endif
std::stack< UniquePtr<SharedSurface> > mScraps;
UniquePtrQueue<SharedSurface> mScraps;
mutable Monitor mMonitor;
bool mIsAlive;