57 |
|
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; |
58 |
|
|
59 |
|
// fields are non-private to simpify nested class access |
60 |
< |
Object[] array; |
60 |
> |
volatile Object[] array; |
61 |
|
final SequenceLock lock; |
62 |
< |
int count; |
62 |
> |
volatile int count; |
63 |
|
final int capacityIncrement; |
64 |
|
|
65 |
|
/** |
201 |
|
|
202 |
|
final void rawAdd(Object e) { |
203 |
|
int n = count; |
204 |
< |
if (n >= array.length) |
204 |
> |
Object[] items = array; |
205 |
> |
if (n < items.length) |
206 |
> |
items[n] = e; |
207 |
> |
else { |
208 |
|
grow(n + 1); |
209 |
< |
array[n] = e; |
209 |
> |
array[n] = e; |
210 |
> |
} |
211 |
|
count = n + 1; |
212 |
|
} |
213 |
|
|
217 |
|
throw new ArrayIndexOutOfBoundsException(index); |
218 |
|
if (n >= array.length) |
219 |
|
grow(n + 1); |
220 |
+ |
Object[] items = array; |
221 |
|
if (index < n) |
222 |
< |
System.arraycopy(array, index, array, index + 1, n - index); |
223 |
< |
array[index] = e; |
222 |
> |
System.arraycopy(items, index, items, index + 1, n - index); |
223 |
> |
items[index] = e; |
224 |
|
count = n + 1; |
225 |
|
} |
226 |
|
|
234 |
|
int newCount = n + len; |
235 |
|
if (newCount >= array.length) |
236 |
|
grow(newCount); |
237 |
< |
int mv = count - index; |
237 |
> |
Object[] items = array; |
238 |
> |
int mv = n - index; |
239 |
|
if (mv > 0) |
240 |
< |
System.arraycopy(array, index, array, index + len, mv); |
241 |
< |
System.arraycopy(elements, 0, array, index, len); |
240 |
> |
System.arraycopy(items, index, items, index + len, mv); |
241 |
> |
System.arraycopy(elements, 0, items, index, len); |
242 |
|
count = newCount; |
243 |
|
return true; |
244 |
|
} |
245 |
|
|
246 |
|
final boolean rawRemoveAt(int index) { |
247 |
+ |
Object[] items = array; |
248 |
|
int n = count - 1; |
249 |
|
if (index < 0 || index > n) |
250 |
|
return false; |
251 |
|
int mv = n - index; |
252 |
|
if (mv > 0) |
253 |
< |
System.arraycopy(array, index + 1, array, index, mv); |
254 |
< |
array[n] = null; |
253 |
> |
System.arraycopy(items, index + 1, items, index, mv); |
254 |
> |
items[n] = null; |
255 |
|
count = n; |
256 |
|
return true; |
257 |
|
} |
288 |
|
if (c != this) { |
289 |
|
lock.lock(); |
290 |
|
try { |
291 |
+ |
Object[] items = array; |
292 |
|
int i = origin; |
293 |
|
int n = count; |
294 |
|
int fence = bound < 0 || bound > n ? n : bound; |
295 |
|
while (i >= 0 && i < fence) { |
296 |
< |
if (c.contains(array[i])) |
296 |
> |
if (c.contains(items[i])) |
297 |
|
++i; |
298 |
|
else { |
299 |
|
--fence; |
300 |
|
int mv = --count - i; |
301 |
|
if (mv > 0) |
302 |
< |
System.arraycopy(array, i + 1, array, i, mv); |
302 |
> |
System.arraycopy(items, i + 1, items, i, mv); |
303 |
|
removed = true; |
304 |
|
} |
305 |
|
} |
311 |
|
} |
312 |
|
|
313 |
|
final void internalClear(int origin, int bound) { |
314 |
+ |
Object[] items = array; |
315 |
|
int n = count; |
316 |
|
int fence = bound < 0 || bound > n ? n : bound; |
317 |
|
if (origin >= 0 && origin < fence) { |
319 |
|
int newCount = n - removed; |
320 |
|
int mv = n - (origin + removed); |
321 |
|
if (mv > 0) |
322 |
< |
System.arraycopy(array, origin + removed, array, origin, mv); |
322 |
> |
System.arraycopy(items, origin + removed, items, origin, mv); |
323 |
|
for (int i = n; i < newCount; ++i) |
324 |
< |
array[i] = null; |
324 |
> |
items[i] = null; |
325 |
|
count = newCount; |
326 |
|
} |
327 |
|
} |
533 |
|
rlen = 0; |
534 |
|
if (origin < 0 || alen >= rlen) { |
535 |
|
if (rlen > 0) |
536 |
< |
System.arraycopy(array, 0, a, origin, rlen); |
536 |
> |
System.arraycopy(items, 0, a, origin, rlen); |
537 |
|
if (alen > rlen) |
538 |
|
a[rlen] = null; |
539 |
|
result = a; |
540 |
|
} |
541 |
|
else |
542 |
< |
result = (T[]) Arrays.copyOfRange(array, origin, |
542 |
> |
result = (T[]) Arrays.copyOfRange(items, origin, |
543 |
|
fence, a.getClass()); |
544 |
|
if (lock.getSequence() == seq) |
545 |
|
break; |
612 |
|
SequenceLock lock = this.lock; |
613 |
|
lock.lock(); |
614 |
|
try { |
615 |
+ |
Object[] items = array; |
616 |
|
for (int i = 0; i < count; i++) |
617 |
< |
array[i] = null; |
617 |
> |
items[i] = null; |
618 |
|
count = 0; |
619 |
|
} finally { |
620 |
|
lock.unlock(); |
693 |
|
} |
694 |
|
|
695 |
|
public boolean isEmpty() { |
686 |
– |
long ignore = lock.getSequence(); |
696 |
|
return count == 0; |
697 |
|
} |
698 |
|
|
773 |
|
SequenceLock lock = this.lock; |
774 |
|
lock.lock(); |
775 |
|
try { |
776 |
+ |
Object[] items = array; |
777 |
|
if (index < 0 || index >= count) |
778 |
|
throw new ArrayIndexOutOfBoundsException(index); |
779 |
< |
oldValue = array[index]; |
780 |
< |
array[index] = element; |
779 |
> |
oldValue = items[index]; |
780 |
> |
items[index] = element; |
781 |
|
} finally { |
782 |
|
lock.unlock(); |
783 |
|
} |
785 |
|
} |
786 |
|
|
787 |
|
public int size() { |
778 |
– |
long ignore = lock.getSequence(); |
788 |
|
return count; |
789 |
|
} |
790 |
|
|
1021 |
|
if (newSize > n) |
1022 |
|
grow(newSize); |
1023 |
|
else { |
1024 |
+ |
Object[] items = array; |
1025 |
|
for (int i = newSize ; i < n ; i++) |
1026 |
< |
array[i] = null; |
1026 |
> |
items[i] = null; |
1027 |
|
} |
1028 |
|
count = newSize; |
1029 |
|
} finally { |
1047 |
|
SequenceLock lock = this.lock; |
1048 |
|
lock.lock(); |
1049 |
|
try { |
1050 |
< |
if (count < array.length) |
1051 |
< |
array = Arrays.copyOf(array, count); |
1050 |
> |
Object[] items = array; |
1051 |
> |
if (count < items.length) |
1052 |
> |
array = Arrays.copyOf(items, count); |
1053 |
|
} finally { |
1054 |
|
lock.unlock(); |
1055 |
|
} |
1076 |
|
|
1077 |
|
/** See {@link Vector#capacity} */ |
1078 |
|
public int capacity() { |
1068 |
– |
long ignore = lock.getSequence(); |
1079 |
|
return array.length; |
1080 |
|
} |
1081 |
|
|