Do not create an iterator unnecessarily
This commit is contained in:
parent
59f11ed64f
commit
bc5e8b6be1
@ -163,8 +163,12 @@ final class SingleThreadSelectorEventLoop extends SingleThreadEventLoop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void processSelectedKeys() {
|
private void processSelectedKeys() {
|
||||||
|
Set<SelectionKey> selectedKeys = selector.selectedKeys();
|
||||||
|
if (selectedKeys.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Iterator<SelectionKey> i;
|
Iterator<SelectionKey> i;
|
||||||
for (i = selector.selectedKeys().iterator(); i.hasNext();) {
|
for (i = selectedKeys.iterator(); i.hasNext();) {
|
||||||
final SelectionKey k = i.next();
|
final SelectionKey k = i.next();
|
||||||
i.remove();
|
i.remove();
|
||||||
final Channel ch = (Channel) k.attachment();
|
final Channel ch = (Channel) k.attachment();
|
||||||
@ -190,7 +194,11 @@ final class SingleThreadSelectorEventLoop extends SingleThreadEventLoop {
|
|||||||
|
|
||||||
if (cleanUpCancelledKeys()) {
|
if (cleanUpCancelledKeys()) {
|
||||||
// Create the iterator again to avoid ConcurrentModificationException
|
// Create the iterator again to avoid ConcurrentModificationException
|
||||||
i = selector.selectedKeys().iterator();
|
if (selectedKeys.isEmpty()) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
i = selectedKeys.iterator();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user