diff --git a/base/src/nsDeque.cpp b/base/src/nsDeque.cpp index ccff44af4b27..bd573d00aabf 100644 --- a/base/src/nsDeque.cpp +++ b/base/src/nsDeque.cpp @@ -18,6 +18,7 @@ #include "nsDeque.h" +#include "nsCRT.h" /** * Standard constructor @@ -65,8 +66,7 @@ PRInt32 nsDeque::GetSize(void) const { * @return */ nsDeque& nsDeque::Empty() { - for(int i=0;i0) { + int offset=mOrigin+mSize; + if(offset>=mCapacity) + offset-=mCapacity; + result=mData[offset]; + mData[offset]=0; + mSize--; + if(0==mSize) + mOrigin=0; + } + return result; +} + /** * Call this to retrieve the ith element from this container. * Keep in mind that accessing the underlying elements is @@ -204,7 +228,8 @@ nsDequeIterator nsDeque::End(void) const{ * @return *this */ const nsDeque& nsDeque::ForEach(nsDequeFunctor& aFunctor) const{ - for(int i=0;i0) { + int offset=mOrigin+mSize; + if(offset>=mCapacity) + offset-=mCapacity; + result=mData[offset]; + mData[offset]=0; + mSize--; + if(0==mSize) + mOrigin=0; + } + return result; +} + /** * Call this to retrieve the ith element from this container. * Keep in mind that accessing the underlying elements is @@ -204,7 +228,8 @@ nsDequeIterator nsDeque::End(void) const{ * @return *this */ const nsDeque& nsDeque::ForEach(nsDequeFunctor& aFunctor) const{ - for(int i=0;i