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.16 by jsr166, Sat Dec 31 05:35:16 2011 UTC vs.
Revision 1.19 by jsr166, Sat Dec 31 06:21:46 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 667 | Line 663 | public class ReadMostlyVector<E>
663      }
664  
665      public int indexOf(Object o) {
666 <        final SequenceLock lock = this.lock;
671 <        for (;;) {
672 <            long seq = lock.awaitAvailability();
673 <            Object[] items = array;
674 <            int n = count;
675 <            if (n <= items.length) {
676 <                for (int i = 0; i < n; ++i) {
677 <                    Object e = items[i];
678 <                    if (lock.getSequence() != seq) {
679 <                        lock.lock();
680 <                        try {
681 <                            return rawIndexOf(o, 0, count);
682 <                        } finally {
683 <                            lock.unlock();
684 <                        }
685 <                    }
686 <                    else if ((o == null) ? e == null : o.equals(e))
687 <                        return i;
688 <                }
689 <                return -1;
690 <            }
691 <        }
666 >        return indexOf(o, 0);
667      }
668  
669      public boolean isEmpty() {
# Line 895 | Line 870 | public class ReadMostlyVector<E>
870          for (;;) {
871              long seq = lock.awaitAvailability();
872              Object[] items = array;
898            int len = items.length;
873              int n = count;
900            if (n > len)
901                continue;
902            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
909 <                    return e;
879 >                return e;
880              }
881          }
882      }
# Line 917 | Line 887 | public class ReadMostlyVector<E>
887          for (;;) {
888              long seq = lock.awaitAvailability();
889              Object[] items = array;
920            int len = items.length;
890              int n = count;
922            if (n > len)
923                continue;
924            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
931 <                    return e;
896 >                return e;
897              }
898          }
899      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines