Avoid unnecessary boxing/unboxing

Motivation:

Boxing/unboxing can be avoided.

Modifications:

Use parseInt/parseLong to avoid unnecessary boxing/unboxing.

Result:

Remove unnecessary boxing/unboxing.
This commit is contained in:
Xiaoyan Lin 2016-01-07 23:03:12 -08:00 committed by Norman Maurer
parent b4be040f30
commit 751ed6cc94
4 changed files with 5 additions and 5 deletions

View File

@ -233,7 +233,7 @@ public final class ClientCookieDecoder extends CookieDecoder {
private void setMaxAge(String value) { private void setMaxAge(String value) {
try { try {
maxAge = Math.max(Long.valueOf(value), 0L); maxAge = Math.max(Long.parseLong(value), 0L);
} catch (NumberFormatException e1) { } catch (NumberFormatException e1) {
// ignore failure to parse -> treat as session cookie // ignore failure to parse -> treat as session cookie
} }

View File

@ -47,7 +47,7 @@ public final class Http2ExampleUtil {
*/ */
public static int toInt(String string, int defaultValue) { public static int toInt(String string, int defaultValue) {
if (string != null && !string.isEmpty()) { if (string != null && !string.isEmpty()) {
return Integer.valueOf(string); return Integer.parseInt(string);
} }
return defaultValue; return defaultValue;
} }

View File

@ -24,7 +24,7 @@ import static io.netty.handler.codec.http.HttpUtil.setContentLength;
import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST; import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST;
import static io.netty.handler.codec.http.HttpResponseStatus.OK; import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
import static java.lang.Integer.valueOf; import static java.lang.Integer.parseInt;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
@ -77,7 +77,7 @@ public class Http2RequestHandler extends SimpleChannelInboundHandler<FullHttpReq
private void handleImage(String x, String y, ChannelHandlerContext ctx, String streamId, int latency, private void handleImage(String x, String y, ChannelHandlerContext ctx, String streamId, int latency,
FullHttpRequest request) { FullHttpRequest request) {
ByteBuf image = ImageCache.INSTANCE.image(valueOf(x), valueOf(y)); ByteBuf image = ImageCache.INSTANCE.image(parseInt(x), parseInt(y));
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, image.duplicate()); FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, image.duplicate());
response.headers().set(CONTENT_TYPE, "image/jpeg"); response.headers().set(CONTENT_TYPE, "image/jpeg");
sendResponse(ctx, streamId, latency, response, request); sendResponse(ctx, streamId, latency, response, request);

View File

@ -184,7 +184,7 @@ public class SimpleChannelPool implements ChannelPool {
assert ch.eventLoop().inEventLoop(); assert ch.eventLoop().inEventLoop();
if (future.isSuccess()) { if (future.isSuccess()) {
if (future.getNow() == Boolean.TRUE) { if (future.getNow()) {
try { try {
ch.attr(POOL_KEY).set(this); ch.attr(POOL_KEY).set(this);
handler.channelAcquired(ch); handler.channelAcquired(ch);