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.18 by jsr166, Sat Dec 31 05:50:22 2011 UTC vs.
Revision 1.22 by jsr166, Sat Dec 31 21:16:14 2011 UTC

# Line 49 | Line 49 | public class ReadMostlyVector<E>
49       * read-only mode, and then lock. When in read-only mode, they
50       * validate only at the end of an array scan unless the element is
51       * actually used (for example, as an argument of method equals).
52 +     *
53 +     * We rely on some invariants that are always true, even for field
54 +     * reads in read-only mode that have not yet been validated:
55 +     * - array != null
56 +     * - count >= 0
57       */
58  
59      /**
# Line 686 | Line 691 | public class ReadMostlyVector<E>
691                      if (lock.getSequence() != seq) {
692                          lock.lock();
693                          try {
694 <                            return rawLastIndexOf(o, 0, count);
694 >                            return rawLastIndexOf(o, count - 1, 0);
695                          } finally {
696                              lock.unlock();
697                          }
# Line 870 | Line 875 | public class ReadMostlyVector<E>
875          for (;;) {
876              long seq = lock.awaitAvailability();
877              Object[] items = array;
873            int len = items.length;
878              int n = count;
875            if (n > len)
876                continue;
877            boolean empty = (n == 0);
879              @SuppressWarnings("unchecked")
880 <            E e = empty ? null : (E) items[0];
880 >            E e = (items.length > 0) ? (E) items[0] : null;
881              if (lock.getSequence() == seq) {
882 <                if (empty)
882 >                if (n <= 0)
883                      throw new NoSuchElementException();
884 <                else
884 <                    return e;
884 >                return e;
885              }
886          }
887      }
# Line 892 | Line 892 | public class ReadMostlyVector<E>
892          for (;;) {
893              long seq = lock.awaitAvailability();
894              Object[] items = array;
895            int len = items.length;
895              int n = count;
897            if (n > len)
898                continue;
899            boolean empty = (n == 0);
896              @SuppressWarnings("unchecked")
897 <            E e = empty ? null : (E) items[n - 1];
897 >            E e = (n > 0 && items.length >= n) ? (E) items[n - 1] : null;
898              if (lock.getSequence() == seq) {
899 <                if (empty)
899 >                if (n <= 0)
900                      throw new NoSuchElementException();
901 <                else
906 <                    return e;
901 >                return e;
902              }
903          }
904      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines