From b53cf045a7718766da8edd9499c657e77b314bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=B6=E6=97=A0=E4=B8=A4=E4=B8=B6?= <442367943@qq.com> Date: Wed, 30 May 2018 21:33:39 +0800 Subject: [PATCH] SelectedSelectionKeySet should only be created if the set can be instrumented Motivation: If we can not replace the internal used Set of the Selector there is no need to create an SelectedSelectionKeySet instance. Modification: Only create SelectedSelectionKeySet if we will replace the internal set. Result: Less object creation in some cases and cleaner code. --- transport/src/main/java/io/netty/channel/nio/NioEventLoop.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java b/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java index d71e3f955d..5e22174112 100644 --- a/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java +++ b/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java @@ -179,8 +179,6 @@ public final class NioEventLoop extends SingleThreadEventLoop { return new SelectorTuple(unwrappedSelector); } - final SelectedSelectionKeySet selectedKeySet = new SelectedSelectionKeySet(); - Object maybeSelectorImplClass = AccessController.doPrivileged(new PrivilegedAction() { @Override public Object run() { @@ -206,6 +204,7 @@ public final class NioEventLoop extends SingleThreadEventLoop { } final Class selectorImplClass = (Class) maybeSelectorImplClass; + final SelectedSelectionKeySet selectedKeySet = new SelectedSelectionKeySet(); Object maybeException = AccessController.doPrivileged(new PrivilegedAction() { @Override