445 |
|
int i, end, to, todo; |
446 |
|
todo = (end = (i = head) + size) |
447 |
|
- (to = (es.length - end >= 0) ? end : es.length); |
448 |
< |
for (;; to = todo, i = 0, todo = 0) { |
448 |
> |
for (;; to = todo, todo = 0, i = 0) { |
449 |
|
for (; i < to; i++) |
450 |
|
if (o.equals(es[i])) { |
451 |
|
delete(i); |
867 |
|
int i, end, to, todo; |
868 |
|
todo = (end = (i = head) + size) |
869 |
|
- (to = (es.length - end >= 0) ? end : es.length); |
870 |
< |
for (;; to = todo, i = 0, todo = 0) { |
870 |
> |
for (;; to = todo, todo = 0, i = 0) { |
871 |
|
for (; i < to; i++) |
872 |
|
action.accept((E) es[i]); |
873 |
|
if (todo == 0) break; |
885 |
|
int end, to, todo; |
886 |
|
todo = (end = i + remaining) |
887 |
|
- (to = (es.length - end >= 0) ? end : es.length); |
888 |
< |
for (;; to = todo, i = 0, todo = 0) { |
888 |
> |
for (;; to = todo, todo = 0, i = 0) { |
889 |
|
for (; i < to; i++) |
890 |
|
action.accept(nonNullElementAt(es, i)); |
891 |
|
if (todo == 0) break; |
906 |
|
int i, end, to, todo; |
907 |
|
todo = (end = (i = head) + size) |
908 |
|
- (to = (es.length - end >= 0) ? end : es.length); |
909 |
< |
for (;; to = todo, i = 0, todo = 0) { |
909 |
> |
for (;; to = todo, todo = 0, i = 0) { |
910 |
|
for (; i < to; i++) |
911 |
|
es[i] = operator.apply((E) es[i]); |
912 |
|
if (todo == 0) break; |
967 |
|
throw ex; |
968 |
|
} finally { |
969 |
|
size -= deleted; |
970 |
< |
clearSlice(es, j, deleted); |
970 |
> |
circularClear(es, j, deleted); |
971 |
|
// checkInvariants(); |
972 |
|
} |
973 |
|
} |
986 |
|
int i, end, to, todo; |
987 |
|
todo = (end = (i = head) + size) |
988 |
|
- (to = (es.length - end >= 0) ? end : es.length); |
989 |
< |
for (;; to = todo, i = 0, todo = 0) { |
989 |
> |
for (;; to = todo, todo = 0, i = 0) { |
990 |
|
for (; i < to; i++) |
991 |
|
if (o.equals(es[i])) |
992 |
|
return true; |
1018 |
|
* The deque will be empty after this call returns. |
1019 |
|
*/ |
1020 |
|
public void clear() { |
1021 |
< |
clearSlice(elements, head, size); |
1021 |
> |
circularClear(elements, head, size); |
1022 |
|
size = head = 0; |
1023 |
|
// checkInvariants(); |
1024 |
|
} |
1025 |
|
|
1026 |
|
/** |
1027 |
< |
* Nulls out count elements, starting at array index i. |
1027 |
> |
* Nulls out count elements, starting at array index from. |
1028 |
|
*/ |
1029 |
< |
private static void clearSlice(Object[] es, int i, int count) { |
1029 |
> |
private static void circularClear(Object[] es, int from, int count) { |
1030 |
|
int end, to, todo; |
1031 |
< |
todo = (end = i + count) |
1031 |
> |
todo = (end = from + count) |
1032 |
|
- (to = (es.length - end >= 0) ? end : es.length); |
1033 |
< |
for (;; to = todo, i = 0, todo = 0) { |
1034 |
< |
Arrays.fill(es, i, to, null); |
1033 |
> |
for (;; to = todo, todo = 0, from = 0) { |
1034 |
> |
Arrays.fill(es, from, to, null); |
1035 |
|
if (todo == 0) break; |
1036 |
|
} |
1037 |
|
} |
1055 |
|
|
1056 |
|
private <T> T[] toArray(Class<T[]> klazz) { |
1057 |
|
final Object[] es = elements; |
1058 |
– |
final int capacity = es.length; |
1059 |
– |
final int head = this.head, end = head + size; |
1058 |
|
final T[] a; |
1059 |
< |
if (end >= 0) { |
1059 |
> |
final int head, len, end, todo; |
1060 |
> |
todo = size - (len = Math.min(size, es.length - (head = this.head))); |
1061 |
> |
if ((end = head + size) >= 0) { |
1062 |
|
a = Arrays.copyOfRange(es, head, end, klazz); |
1063 |
|
} else { |
1064 |
|
// integer overflow! |
1065 |
|
a = Arrays.copyOfRange(es, 0, size, klazz); |
1066 |
< |
System.arraycopy(es, head, a, 0, capacity - head); |
1066 |
> |
System.arraycopy(es, head, a, 0, len); |
1067 |
|
} |
1068 |
< |
if (end - capacity > 0) |
1069 |
< |
System.arraycopy(es, 0, a, capacity - head, end - capacity); |
1068 |
> |
if (todo > 0) |
1069 |
> |
System.arraycopy(es, 0, a, len, todo); |
1070 |
|
return a; |
1071 |
|
} |
1072 |
|
|
1112 |
|
if ((size = this.size) > a.length) |
1113 |
|
return toArray((Class<T[]>) a.getClass()); |
1114 |
|
final Object[] es = elements; |
1115 |
< |
final int head = this.head, end = head + size; |
1116 |
< |
final int front = (es.length - end >= 0) ? size : es.length - head; |
1117 |
< |
System.arraycopy(es, head, a, 0, front); |
1118 |
< |
if (front < size) |
1119 |
< |
System.arraycopy(es, 0, a, front, size - front); |
1115 |
> |
int i, j, len, todo; |
1116 |
> |
todo = size - (len = Math.min(size, es.length - (i = head))); |
1117 |
> |
for (j = 0;; j += len, len = todo, todo = 0, i = 0) { |
1118 |
> |
System.arraycopy(es, i, a, j, len); |
1119 |
> |
if (todo == 0) break; |
1120 |
> |
} |
1121 |
|
if (size < a.length) |
1122 |
|
a[size] = null; |
1123 |
|
return a; |
1164 |
|
int i, end, to, todo; |
1165 |
|
todo = (end = (i = head) + size) |
1166 |
|
- (to = (es.length - end >= 0) ? end : es.length); |
1167 |
< |
for (;; to = todo, i = 0, todo = 0) { |
1167 |
> |
for (;; to = todo, todo = 0, i = 0) { |
1168 |
|
for (; i < to; i++) |
1169 |
|
s.writeObject(es[i]); |
1170 |
|
if (todo == 0) break; |