提交 40aa4456 编写于 作者: A akhil

8005051: optimized defaults for Iterator.forEachRemaining

Reviewed-by: alanb, mduigou, psandoz, ulfzibis
Contributed-by: NAkhil Arora <akhil.arora@oracle.com>
上级 ab02f042
...@@ -29,10 +29,6 @@ import java.util.function.Consumer; ...@@ -29,10 +29,6 @@ import java.util.function.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
/** /**
* Resizable-array implementation of the <tt>List</tt> interface. Implements * Resizable-array implementation of the <tt>List</tt> interface. Implements
* all optional list operations, and permits all elements, including * all optional list operations, and permits all elements, including
......
...@@ -957,6 +957,7 @@ public class LinkedList<E> ...@@ -957,6 +957,7 @@ public class LinkedList<E>
next = next.next; next = next.next;
nextIndex++; nextIndex++;
} }
lastReturned = next;
checkForComodification(); checkForComodification();
} }
......
...@@ -29,8 +29,6 @@ import java.util.function.Consumer; ...@@ -29,8 +29,6 @@ import java.util.function.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
import java.util.function.Consumer;
/** /**
* The {@code Vector} class implements a growable array of * The {@code Vector} class implements a growable array of
* objects. Like an array, it contains components that can be * objects. Like an array, it contains components that can be
...@@ -1161,7 +1159,7 @@ public class Vector<E> ...@@ -1161,7 +1159,7 @@ public class Vector<E>
public void forEachRemaining(Consumer<? super E> action) { public void forEachRemaining(Consumer<? super E> action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
synchronized (Vector.this) { synchronized (Vector.this) {
final int size = Vector.this.elementCount; final int size = elementCount;
int i = cursor; int i = cursor;
if (i >= size) { if (i >= size) {
return; return;
......
...@@ -1059,6 +1059,17 @@ public class CopyOnWriteArrayList<E> ...@@ -1059,6 +1059,17 @@ public class CopyOnWriteArrayList<E>
public void add(E e) { public void add(E e) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
@SuppressWarnings("unchecked")
public void forEachRemaining(Consumer<? super E> action) {
Objects.requireNonNull(action);
final int size = snapshot.length;
for (int i=cursor; i < size; i++) {
action.accept((E) snapshot[i]);
}
cursor = size;
}
} }
/** /**
...@@ -1367,6 +1378,15 @@ public class CopyOnWriteArrayList<E> ...@@ -1367,6 +1378,15 @@ public class CopyOnWriteArrayList<E>
public void add(E e) { public void add(E e) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
@SuppressWarnings("unchecked")
public void forEachRemaining(Consumer<? super E> action) {
Objects.requireNonNull(action);
while (nextIndex() < size) {
action.accept(it.next());
}
}
} }
// Support for resetting lock while deserializing // Support for resetting lock while deserializing
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册