Exemplo n.º 1
0
 void Add(T &&e)
 {
     GrowCapacity(1);
     sPlacementNew<T>(Last);
     *Last = sMove(e);
     Last++;
 }
Exemplo n.º 2
0
/**
 * This method adds an item to the end of the deque.
 * This operation has the potential to cause the
 * underlying buffer to resize.
 *
 * @param   aItem: new item to be added to deque
 */
bool nsDeque::Push(void* aItem, const fallible_t&) {
  if (mSize==mCapacity && !GrowCapacity()) {
    return false;
  }
  mData[modulus(mOrigin + mSize, mCapacity)]=aItem;
  mSize++;
  return true;
}
Exemplo n.º 3
0
/**
 * This method adds an item to the end of the deque.
 * This operation has the potential to cause the
 * underlying buffer to resize.
 *
 * @param   aItem: new item to be added to deque
 * @return  *this
 */
nsDeque& nsDeque::Push(void* aItem) {
  if (mSize==mCapacity && !GrowCapacity()) {
    NS_WARNING("out of memory");
    return *this;
  }
  mData[modulus(mOrigin + mSize, mCapacity)]=aItem;
  mSize++;
  return *this;
}
Exemplo n.º 4
0
/**
 * This method adds an item to the front of the deque.
 * This operation has the potential to cause the
 * underlying buffer to resize.
 *
 * --Commments for GrowCapacity() case
 * We've grown and shifted which means that the old
 * final element in the deque is now the first element
 * in the deque.  This is temporary.
 * We haven't inserted the new element at the front.
 *
 * To continue with the idea of having the front at zero
 * after a grow, we move the old final item (which through
 * the voodoo of mOrigin-- is now the first) to its final
 * position which is conveniently the old length.
 *
 * Note that this case only happens when the deque is full.
 * [And that pieces of this magic only work if the deque is full.]
 * picture:
 *   [ABCDEFGH] @[mOrigin:3]:D.
 * Task: PushFront("Z")
 * shift mOrigin so, @[mOrigin:2]:C
 * stretch and rearrange: (mOrigin:0)
 *   [CDEFGHAB ________ ________ ________]
 * copy: (The second C is currently out of bounds)
 *   [CDEFGHAB C_______ ________ ________]
 * later we will insert Z:
 *   [ZDEFGHAB C_______ ________ ________]
 * and increment size: 9. (C is no longer out of bounds)
 * --
 * @param   aItem: new item to be added to deque
 */
bool nsDeque::PushFront(void* aItem, const fallible_t&) {
  mOrigin--;
  modasgn(mOrigin,mCapacity);
  if (mSize==mCapacity) {
    if (!GrowCapacity()) {
      return false;
    }
    /* Comments explaining this are above*/
    mData[mSize]=mData[mOrigin];
  }
  mData[mOrigin]=aItem;
  mSize++;
  return true;
}
Exemplo n.º 5
0
/**
 * This method adds an item to the front of the deque.
 * This operation has the potential to cause the
 * underlying buffer to resize.
 *
 * --Commments for GrowCapacity() case
 * We've grown and shifted which means that the old
 * final element in the deque is now the first element
 * in the deque.  This is temporary.
 * We haven't inserted the new element at the front.
 *
 * To continue with the idea of having the front at zero
 * after a grow, we move the old final item (which through
 * the voodoo of mOrigin-- is now the first) to its final
 * position which is conveniently the old length.
 *
 * Note that this case only happens when the deque is full.
 * [And that pieces of this magic only work if the deque is full.]
 * picture:
 *   [ABCDEFGH] @[mOrigin:3]:D.
 * Task: PushFront("Z")
 * shift mOrigin so, @[mOrigin:2]:C
 * stretch and rearrange: (mOrigin:0)
 *   [CDEFGHAB ________ ________ ________]
 * copy: (The second C is currently out of bounds)
 *   [CDEFGHAB C_______ ________ ________]
 * later we will insert Z:
 *   [ZDEFGHAB C_______ ________ ________]
 * 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) {
  mOrigin--;
  modasgn(mOrigin,mCapacity);
  if (mSize==mCapacity) {
    if (!GrowCapacity()) {
      NS_WARNING("out of memory");
      return *this;
    }
    /* Comments explaining this are above*/
    mData[mSize]=mData[mOrigin];
  }
  mData[mOrigin]=aItem;
  mSize++;
  return *this;
}
Exemplo n.º 6
0
    void SetCount(sPtr n)
    {
        T *newlast = First+n;

        while(newlast<Last)
        {
            Last--;
            Last->~T();
        }
        if(newlast>End)
            GrowCapacity(n);
        while(newlast>Last)
        {
            sPlacementNew<T>(Last);
            Last++;
        }
    }
Exemplo n.º 7
0
 void Add(const T &e)
 {
     GrowCapacity(1);
     sPlacementNewConst<T>(Last,e);
     Last++;
 }