зеркало из https://github.com/mozilla/gecko-dev.git
Bug 875557 - Make nsDeque infallible by default. r=bsmedberg
Also remove some unused return values.
This commit is contained in:
Родитель
4ff8c5dfa4
Коммит
41063b6447
|
@ -103,28 +103,23 @@ void nsDeque::SetDeallocator(nsDequeFunctor* aDeallocator){
|
|||
|
||||
/**
|
||||
* Remove all items from container without destroying them.
|
||||
*
|
||||
* @return *this
|
||||
*/
|
||||
nsDeque& nsDeque::Empty() {
|
||||
void nsDeque::Empty() {
|
||||
if (mSize && mData) {
|
||||
memset(mData, 0, mCapacity*sizeof(mData));
|
||||
}
|
||||
mSize=0;
|
||||
mOrigin=0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove and delete all items from container
|
||||
*
|
||||
* @return *this
|
||||
*/
|
||||
nsDeque& nsDeque::Erase() {
|
||||
void nsDeque::Erase() {
|
||||
if (mDeallocator && mSize) {
|
||||
ForEach(*mDeallocator);
|
||||
}
|
||||
return Empty();
|
||||
Empty();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,9 +127,6 @@ nsDeque& nsDeque::Erase() {
|
|||
* Elements in the deque are resequenced so that elements
|
||||
* in the deque are stored sequentially
|
||||
*
|
||||
* If the deque actually overflows, there's very little we can do.
|
||||
* Perhaps this function should return bool/nsresult indicating success/failure.
|
||||
*
|
||||
* @return whether growing succeeded
|
||||
*/
|
||||
bool nsDeque::GrowCapacity() {
|
||||
|
@ -171,15 +163,14 @@ bool nsDeque::GrowCapacity() {
|
|||
* underlying buffer to resize.
|
||||
*
|
||||
* @param aItem: new item to be added to deque
|
||||
* @return *this
|
||||
*/
|
||||
nsDeque& nsDeque::Push(void* aItem) {
|
||||
bool nsDeque::Push(void* aItem, const fallible_t&) {
|
||||
if (mSize==mCapacity && !GrowCapacity()) {
|
||||
return *this;
|
||||
return false;
|
||||
}
|
||||
mData[modulus(mOrigin + mSize, mCapacity)]=aItem;
|
||||
mSize++;
|
||||
return *this;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -213,22 +204,20 @@ nsDeque& nsDeque::Push(void* aItem) {
|
|||
* and increment size: 9. (C is no longer out of bounds)
|
||||
* --
|
||||
* @param aItem: new item to be added to deque
|
||||
* @return *this
|
||||
*/
|
||||
nsDeque& nsDeque::PushFront(void* aItem) {
|
||||
bool nsDeque::PushFront(void* aItem, const fallible_t&) {
|
||||
mOrigin--;
|
||||
modasgn(mOrigin,mCapacity);
|
||||
if (mSize==mCapacity) {
|
||||
if (!GrowCapacity()) {
|
||||
NS_WARNING("out of memory");
|
||||
return *this;
|
||||
return false;
|
||||
}
|
||||
/* Comments explaining this are above*/
|
||||
mData[mSize]=mData[mOrigin];
|
||||
}
|
||||
mData[mOrigin]=aItem;
|
||||
mSize++;
|
||||
return *this;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,7 +25,9 @@
|
|||
#define _NSDEQUE
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsDebug.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/fallible.h"
|
||||
|
||||
/**
|
||||
* The nsDequeFunctor class is used when you want to create
|
||||
|
@ -58,6 +60,7 @@ class nsDequeIterator;
|
|||
|
||||
class NS_COM_GLUE nsDeque {
|
||||
friend class nsDequeIterator;
|
||||
typedef mozilla::fallible_t fallible_t;
|
||||
public:
|
||||
nsDeque(nsDequeFunctor* aDeallocator = nullptr);
|
||||
~nsDeque();
|
||||
|
@ -74,17 +77,27 @@ class NS_COM_GLUE nsDeque {
|
|||
* Appends new member at the end of the deque.
|
||||
*
|
||||
* @param item to store in deque
|
||||
* @return *this
|
||||
*/
|
||||
nsDeque& Push(void* aItem);
|
||||
void Push(void* aItem) {
|
||||
if (!Push(aItem, fallible_t())) {
|
||||
NS_RUNTIMEABORT("OOM");
|
||||
}
|
||||
}
|
||||
|
||||
bool Push(void* aItem, const fallible_t&) NS_WARN_UNUSED_RESULT;
|
||||
|
||||
/**
|
||||
* Inserts new member at the front of the deque.
|
||||
*
|
||||
* @param item to store in deque
|
||||
* @return *this
|
||||
*/
|
||||
nsDeque& PushFront(void* aItem);
|
||||
void PushFront(void* aItem) {
|
||||
if (!PushFront(aItem, fallible_t())) {
|
||||
NS_RUNTIMEABORT("OOM");
|
||||
}
|
||||
}
|
||||
|
||||
bool PushFront(void* aItem, const fallible_t&) NS_WARN_UNUSED_RESULT;
|
||||
|
||||
/**
|
||||
* Remove and return the last item in the container.
|
||||
|
@ -132,19 +145,15 @@ class NS_COM_GLUE nsDeque {
|
|||
|
||||
/**
|
||||
* Remove all items from container without destroying them.
|
||||
*
|
||||
* @return *this
|
||||
*/
|
||||
nsDeque& Empty();
|
||||
void Empty();
|
||||
|
||||
/**
|
||||
* Remove and delete all items from container.
|
||||
* Deletes are handled by the deallocator nsDequeFunctor
|
||||
* which is specified at deque construction.
|
||||
*
|
||||
* @return *this
|
||||
*/
|
||||
nsDeque& Erase();
|
||||
void Erase();
|
||||
|
||||
/**
|
||||
* Creates a new iterator, pointing to the first
|
||||
|
@ -163,13 +172,13 @@ class NS_COM_GLUE nsDeque {
|
|||
nsDequeIterator End() const;
|
||||
|
||||
void* Last() const;
|
||||
|
||||
/**
|
||||
* Call this method when you want to iterate all the
|
||||
* members of the container, passing a functor along
|
||||
* to call your code.
|
||||
*
|
||||
* @param aFunctor object to call for each member
|
||||
* @return *this
|
||||
*/
|
||||
void ForEach(nsDequeFunctor& aFunctor) const;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче