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 |
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 |
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; |
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; |
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; |
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 |
|
} |
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) |
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; |