1103 |
|
* @return the number of elements in this deque |
1104 |
|
*/ |
1105 |
|
public int size() { |
1106 |
< |
int count = 0; |
1107 |
< |
for (Node<E> p = first(); p != null; p = succ(p)) |
1108 |
< |
if (p.item != null) |
1109 |
< |
// Collection.size() spec says to max out |
1110 |
< |
if (++count == Integer.MAX_VALUE) |
1111 |
< |
break; |
1112 |
< |
return count; |
1106 |
> |
restartFromHead: for (;;) { |
1107 |
> |
int count = 0; |
1108 |
> |
for (Node<E> p = first(); p != null;) { |
1109 |
> |
if (p.item != null) |
1110 |
> |
if (++count == Integer.MAX_VALUE) |
1111 |
> |
break; // @see Collection.size() |
1112 |
> |
Node<E> next = p.next; |
1113 |
> |
if (p == next) |
1114 |
> |
continue restartFromHead; |
1115 |
> |
p = next; |
1116 |
> |
} |
1117 |
> |
return count; |
1118 |
> |
} |
1119 |
|
} |
1120 |
|
|
1121 |
|
/** |