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.2 by dl, Sat Jul 16 13:20:35 2011 UTC vs.
Revision 1.3 by jsr166, Sat Jul 16 14:56:30 2011 UTC

# Line 12 | Line 12 | import java.util.*;
12   * A class with the same methods and array-based characteristics as
13   * {@link java.util.Vector} but with reduced contention and improved
14   * throughput when invocations of read-only methods by multiple
15 < * threads are most common.
15 > * threads are most common.
16   *
17   * <p> The iterators returned by this class's {@link #iterator()
18   * iterator} and {@link #listIterator(int) listIterator} methods are
# Line 40 | Line 40 | public class ReadMostlyVector<E> impleme
40       * Short methods,including get(index), continually retry obtaining
41       * a snapshot of array, count, and element, using sequence number
42       * to validate.
43 <     *
43 >     *
44       * Methods that are potentially O(n) (or worse) try once in
45       * read-only mode, and then lock. When in read-only mode, they
46       * validate only at the end of an array scan unless the element is
# Line 151 | Line 151 | public class ReadMostlyVector<E> impleme
151       * as well as sublist and iterator classes.
152       */
153  
154 <    final int validatedIndexOf(Object x, Object[] items, int index, int fence,
154 >    final int validatedIndexOf(Object x, Object[] items, int index, int fence,
155                                 long seq) {
156          for (int i = index; i < fence; ++i) {
157              Object e = items[i];
158              if (lock.getSequence() != seq)
159                  break;
160 <            if (x == null? e == null : (e != null && x.equals(e)))
160 >            if ((x == null) ? e == null : (e != null && x.equals(e)))
161                  return i;
162          }
163          return -1;
# Line 167 | Line 167 | public class ReadMostlyVector<E> impleme
167          Object[] items = array;
168          for (int i = index; i < fence; ++i) {
169              Object e = items[i];
170 <            if (x == null? e == null : (e != null && x.equals(e)))
170 >            if ((x == null) ? e == null : (e != null && x.equals(e)))
171                  return i;
172          }
173          return -1;
174      }
175  
176 <    final int validatedLastIndexOf(Object x, Object[] items,
176 >    final int validatedLastIndexOf(Object x, Object[] items,
177                                     int index, int origin, long seq) {
178          for (int i = index; i >= origin; --i) {
179              Object e = items[i];
180              if (lock.getSequence() != seq)
181                  break;
182 <            if (x == null? e == null : (e != null && x.equals(e)))
182 >            if ((x == null) ? e == null : (e != null && x.equals(e)))
183                  return i;
184          }
185          return -1;
# Line 189 | Line 189 | public class ReadMostlyVector<E> impleme
189          Object[] items = array;
190          for (int i = index; i >= origin; --i) {
191              Object e = items[i];
192 <            if (x == null? e == null : (e != null && x.equals(e)))
192 >            if ((x == null) ? e == null : (e != null && x.equals(e)))
193                  return i;
194          }
195          return -1;
# Line 376 | Line 376 | public class ReadMostlyVector<E> impleme
376                          Object y = items[i];
377                          if (lock.getSequence() != seq)
378                              continue outer;
379 <                        if (x == null? y != null : (y == null || !x.equals(y))) {
379 >                        if ((x == null) ? y != null : (y == null || !x.equals(y))) {
380                              equal = false;
381                              break;
382                          }
# Line 527 | Line 527 | public class ReadMostlyVector<E> impleme
527                          a[rlen] = null;
528                      result = a;
529                  }
530 <                else
530 >                else
531                      result = (T[]) Arrays.copyOfRange(array, origin,
532                                                        fence, a.getClass());
533                  if (lock.getSequence() == seq)
# Line 1383 | Line 1383 | public class ReadMostlyVector<E> impleme
1383              Object[] items = list.array;
1384              int c = list.count;
1385              if (c <= items.length) {
1386 <                int idx = list.validatedLastIndexOf(o, items, offset+size-1,
1386 >                int idx = list.validatedLastIndexOf(o, items, offset+size-1,
1387                                                      offset, seq);
1388                  if (lock.getSequence() == seq)
1389                      return idx < 0 ? -1 : idx - offset;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines