ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/ArrayDeque.java
(Generate patch)

Comparing jsr166/src/main/java/util/ArrayDeque.java (file contents):
Revision 1.16 by dl, Wed Sep 14 23:49:59 2005 UTC vs.
Revision 1.17 by dl, Thu Sep 15 16:55:24 2005 UTC

# Line 594 | Line 594 | public class ArrayDeque<E> extends Abstr
594          public void remove() {
595              if (lastRet < 0)
596                  throw new IllegalStateException();
597 <            if (delete(lastRet))
598 <                cursor--;
597 >            if (delete(lastRet)) // if left-shifted, undo increment in next()
598 >                cursor = (cursor - 1) & (elements.length - 1);
599              lastRet = -1;
600              fence = tail;
601          }
# Line 604 | Line 604 | public class ArrayDeque<E> extends Abstr
604  
605      private class DescendingIterator implements Iterator<E> {
606          /*
607 <         * This class is nearly a mirror-image of DeqIterator. It
608 <         * shares the same structure, but not many actual lines of
609 <         * code. The only asymmetric part is that to simplify some
610 <         * checks, indices are anded with length mask only on array
611 <         * access rather than on each update.
607 >         * This class is nearly a mirror-image of DeqIterator, using
608 >         * (tail-1) instead of head for initial cursor, (head-1)
609 >         * instead of tail for fence, and elements.length instead of -1
610 >         * for sentinel. It shares the same structure, but not many
611 >         * actual lines of code.
612           */
613 <        private int cursor = tail - 1;
614 <        private int fence = head - 1;
613 >        private int cursor = (tail - 1) & (elements.length - 1);
614 >        private int fence =  (head - 1) & (elements.length - 1);
615          private int lastRet = elements.length;
616  
617          public boolean hasNext() {
# Line 622 | Line 622 | public class ArrayDeque<E> extends Abstr
622              E result;
623              if (cursor == fence)
624                  throw new NoSuchElementException();
625 <            if ((head - 1) != fence ||
626 <                (result = elements[cursor & (elements.length-1)]) == null)
625 >            if (((head - 1) & (elements.length - 1)) != fence ||
626 >                (result = elements[cursor]) == null)
627                  throw new ConcurrentModificationException();
628              lastRet = cursor;
629 <            cursor--;
629 >            cursor = (cursor - 1) & (elements.length - 1);
630              return result;
631          }
632  
633          public void remove() {
634              if (lastRet >= elements.length)
635                  throw new IllegalStateException();
636 <            if (delete(lastRet & (elements.length-1)))
637 <                cursor++;
636 >            if (!delete(lastRet))
637 >                cursor = (cursor + 1) & (elements.length - 1);
638              lastRet = elements.length;
639 <            fence = head - 1;
639 >            fence = (head - 1) & (elements.length - 1);
640          }
641      }
642  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines