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.6 by jsr166, Sun Jul 17 17:17:46 2011 UTC vs.
Revision 1.7 by dl, Mon Jul 18 14:44:32 2011 UTC

# Line 659 | Line 659 | public class ReadMostlyVector<E> impleme
659  
660      public int indexOf(Object o) {
661          SequenceLock lock = this.lock;
662 <        long seq = lock.awaitAvailability();
663 <        Object[] items = array;
664 <        int n = count;
665 <        if (n <= items.length) {
666 <            boolean valid = true;
667 <            for (int i = 0; i < n; ++i) {
668 <                Object e = items[i];
669 <                if (lock.getSequence() == seq) {
670 <                    if ((o == null) ? e == null : o.equals(e))
662 >        for (;;) {
663 >            long seq = lock.awaitAvailability();
664 >            Object[] items = array;
665 >            int n = count;
666 >            if (n <= items.length) {
667 >                for (int i = 0; i < n; ++i) {
668 >                    Object e = items[i];
669 >                    if (lock.getSequence() != seq) {
670 >                        lock.lock();
671 >                        try {
672 >                            return rawIndexOf(o, 0, count);
673 >                        } finally {
674 >                            lock.unlock();
675 >                        }
676 >                    }
677 >                    else if ((o == null) ? e == null : o.equals(e))
678                          return i;
679                  }
673                else {
674                    valid = false;
675                    break;
676                }
677            }
678            if (valid)
680                  return -1;
681 <        }
681 <        lock.lock();
682 <        try {
683 <            return rawIndexOf(o, 0, count);
684 <        } finally {
685 <            lock.unlock();
681 >            }
682          }
683      }
684  
# Line 697 | Line 693 | public class ReadMostlyVector<E> impleme
693  
694      public int lastIndexOf(Object o) {
695          SequenceLock lock = this.lock;
696 <        long seq = lock.awaitAvailability();
697 <        Object[] items = array;
698 <        int n = count;
699 <        if (n <= items.length) {
700 <            int idx = validatedLastIndexOf(o, items, n - 1, 0, seq);
701 <            if (lock.getSequence() == seq)
702 <                return idx;
703 <        }
704 <        lock.lock();
705 <        try {
706 <            return rawLastIndexOf(o, count - 1, 0);
707 <        } finally {
708 <            lock.unlock();
696 >        for (;;) {
697 >            long seq = lock.awaitAvailability();
698 >            Object[] items = array;
699 >            int n = count;
700 >            if (n <= items.length) {
701 >                for (int i = n - 1; i >= 0; --i) {
702 >                    Object e = items[i];
703 >                    if (lock.getSequence() != seq) {
704 >                        lock.lock();
705 >                        try {
706 >                            return rawLastIndexOf(o, 0, count);
707 >                        } finally {
708 >                            lock.unlock();
709 >                        }
710 >                    }
711 >                    else if ((o == null) ? e == null : o.equals(e))
712 >                        return i;
713 >                }
714 >                return -1;
715 >            }
716          }
717      }
718  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines