ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166e/extra/ReadMostlyVector.java
(Generate patch)

Comparing jsr166/src/jsr166e/extra/ReadMostlyVector.java (file contents):
Revision 1.17 by jsr166, Sat Dec 31 05:38:24 2011 UTC vs.
Revision 1.20 by jsr166, Sat Dec 31 18:48:47 2011 UTC

# Line 648 | Line 648 | public class ReadMostlyVector<E>
648              long seq = lock.awaitAvailability();
649              int n = count;
650              Object[] items = array;
651            if (n > items.length)
652                continue;
653            boolean outOfBounds = (index < 0 || index >= n);
651              @SuppressWarnings("unchecked")
652 <            E e = outOfBounds ? null : (E) items[index];
652 >            E e = (index < items.length) ? (E) items[index] : null;
653              if (lock.getSequence() == seq) {
654 <                if (outOfBounds)
654 >                if (index >= n)
655                      throw new ArrayIndexOutOfBoundsException(index);
656 <                else
660 <                    return e;
656 >                return e;
657              }
658          }
659      }
# Line 690 | Line 686 | public class ReadMostlyVector<E>
686                      if (lock.getSequence() != seq) {
687                          lock.lock();
688                          try {
689 <                            return rawLastIndexOf(o, 0, count);
689 >                            return rawLastIndexOf(o, count, 0);
690                          } finally {
691                              lock.unlock();
692                          }
# Line 874 | Line 870 | public class ReadMostlyVector<E>
870          for (;;) {
871              long seq = lock.awaitAvailability();
872              Object[] items = array;
877            int len = items.length;
873              int n = count;
879            if (n > len)
880                continue;
881            boolean empty = (n == 0);
874              @SuppressWarnings("unchecked")
875 <            E e = empty ? null : (E) items[0];
875 >            E e = (items.length > 0) ? (E) items[0] : null;
876              if (lock.getSequence() == seq) {
877 <                if (empty)
877 >                if (n <= 0)
878                      throw new NoSuchElementException();
879 <                else
888 <                    return e;
879 >                return e;
880              }
881          }
882      }
# Line 896 | Line 887 | public class ReadMostlyVector<E>
887          for (;;) {
888              long seq = lock.awaitAvailability();
889              Object[] items = array;
899            int len = items.length;
890              int n = count;
901            if (n > len)
902                continue;
903            boolean empty = (n == 0);
891              @SuppressWarnings("unchecked")
892 <            E e = empty ? null : (E) items[n - 1];
892 >            E e = (n > 0 && items.length >= n) ? (E) items[n - 1] : null;
893              if (lock.getSequence() == seq) {
894 <                if (empty)
894 >                if (n <= 0)
895                      throw new NoSuchElementException();
896 <                else
910 <                    return e;
896 >                return e;
897              }
898          }
899      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines