238:
239: /*
240: * Copy the last element of the next array to the top of this array,
241: * unless this is the first block (in which case there is no next
242: * array).
243: */
244: if (curr.mPrev != null)
245: curr.mElems[0] = curr.mPrev.mElems[curr.mPrev.mElems.length - 1];
246: }
247:
248: /*
249: * The head just lost an element, so it has some more free space. Null
250: * out the lost element and increase the free space.
251: */
252: ++mHead.mFreeSpace;
253: mHead.mElems[mHead.mFreeSpace - 1] = null;
254:
255: /* The whole list just lost an element. */
256: --mSize;
257:
258: /* If the head is entirely free, remove it from the list. */
259: if (mHead.mFreeSpace == mHead.mElems.length) {
260: mHead = mHead.mNext;
261:
262: /*
263: * If there is at least one block left, remove the previous block
264: * from the linked list.
265: */
266: if (mHead != null)
267: mHead.mPrev = null;
268: }
269: }
270:
271: /**
272: * A custom iterator class that traverses the elements of this container in
273: * an intelligent way. The normal iterator will call get repeatedly, which
274: * is slow because it has to continuously scan for the proper location of
275: * the next element. This iterator works by traversing the cells as a proper
276: * linked list.
277: */
278: private final class VListIterator implements Iterator
279: /*
281: * maintain the invariant that if there is a next element, mCurrCell is
282: * non-null and conversely that if mCurrCell is null, there is no next
283: * element.
284: */
285: private VListCell
286: private int mCurrIndex;
287:
288: /*
289: * Stores whether we have something to remove (i.e. whether we've called
290: * next() without an invervening remove()).
291: */
292: private boolean mCanRemove;
293:
294: /**
295: * Constructs a new VListIterator that will traverse the elements of the
296: * containing VList.
297: */
298: public VListIterator() {
299: /*
300: * Scan to the tail using the "pointer chase" algorithm. When this
301: * terminates, prev will hold a pointer to the last element of the
302: * list.
303: */
304: VListCell
305: for (curr = mHead, prev = null; curr != null; prev = curr, curr = curr.mNext)
306: ;
307:
308: /* Set the current cell to the tail. */
309: mCurrCell = prev;
310:
311: /*
312: * If the tail isn't null, it must be a full list of size 1. Set the
313: * current index appropriately.
314: */
315: if (mCurrCell != null)
316: mCurrIndex = 0;
317: }
318:
319: /**
320: * As per our invariant, returns whether mCurrCell is non-null.
321: */
322: public boo