--- jsr166/src/jsr166e/extra/ReadMostlyVector.java 2011/07/17 17:17:46 1.6 +++ jsr166/src/jsr166e/extra/ReadMostlyVector.java 2011/07/19 12:05:09 1.9 @@ -659,30 +659,26 @@ public class ReadMostlyVector impleme public int indexOf(Object o) { SequenceLock lock = this.lock; - long seq = lock.awaitAvailability(); - Object[] items = array; - int n = count; - if (n <= items.length) { - boolean valid = true; - for (int i = 0; i < n; ++i) { - Object e = items[i]; - if (lock.getSequence() == seq) { - if ((o == null) ? e == null : o.equals(e)) + for (;;) { + long seq = lock.awaitAvailability(); + Object[] items = array; + int n = count; + if (n <= items.length) { + for (int i = 0; i < n; ++i) { + Object e = items[i]; + if (lock.getSequence() != seq) { + lock.lock(); + try { + return rawIndexOf(o, 0, count); + } finally { + lock.unlock(); + } + } + else if ((o == null) ? e == null : o.equals(e)) return i; } - else { - valid = false; - break; - } - } - if (valid) return -1; - } - lock.lock(); - try { - return rawIndexOf(o, 0, count); - } finally { - lock.unlock(); + } } } @@ -697,19 +693,26 @@ public class ReadMostlyVector impleme public int lastIndexOf(Object o) { SequenceLock lock = this.lock; - long seq = lock.awaitAvailability(); - Object[] items = array; - int n = count; - if (n <= items.length) { - int idx = validatedLastIndexOf(o, items, n - 1, 0, seq); - if (lock.getSequence() == seq) - return idx; - } - lock.lock(); - try { - return rawLastIndexOf(o, count - 1, 0); - } finally { - lock.unlock(); + for (;;) { + long seq = lock.awaitAvailability(); + Object[] items = array; + int n = count; + if (n <= items.length) { + for (int i = n - 1; i >= 0; --i) { + Object e = items[i]; + if (lock.getSequence() != seq) { + lock.lock(); + try { + return rawLastIndexOf(o, 0, count); + } finally { + lock.unlock(); + } + } + else if ((o == null) ? e == null : o.equals(e)) + return i; + } + return -1; + } } } @@ -802,7 +805,7 @@ public class ReadMostlyVector impleme * Append the element if not present. * * @param e element to be added to this list, if absent - * @return true if the element was added + * @return {@code true} if the element was added */ public boolean addIfAbsent(E e) { boolean added; @@ -857,7 +860,7 @@ public class ReadMostlyVector impleme * Returns an iterator operating over a snapshot copy of the * elements of this collection created upon construction of the * iterator. The iterator does NOT support the - * remove method. + * {@code remove} method. * * @return an iterator over the elements in this list in proper sequence */