From b9abd3c9fc90cda1781a6f2f181735460a13b75d Mon Sep 17 00:00:00 2001 From: Dmitriy Dumanskiy Date: Sat, 4 Feb 2017 01:08:46 +0200 Subject: [PATCH] Cleanup : for loops for arrays to make code easier to read and removed unnecessary toLowerCase() --- buffer/src/main/java/io/netty/buffer/PoolArena.java | 3 +-- .../main/java/io/netty/buffer/PooledByteBufAllocator.java | 4 ++-- .../main/java/io/netty/handler/codec/http2/Http2Error.java | 3 +-- .../handler/codec/compression/Bzip2BlockCompressor.java | 4 ++-- handler/src/main/java/io/netty/handler/ssl/SslHandler.java | 4 ++-- .../src/main/java/io/netty/channel/epoll/IovArray.java | 3 +-- .../io/netty/channel/epoll/NativeDatagramPacketArray.java | 6 +++--- 7 files changed, 12 insertions(+), 15 deletions(-) diff --git a/buffer/src/main/java/io/netty/buffer/PoolArena.java b/buffer/src/main/java/io/netty/buffer/PoolArena.java index fcb428e468..5bb0ab3523 100644 --- a/buffer/src/main/java/io/netty/buffer/PoolArena.java +++ b/buffer/src/main/java/io/netty/buffer/PoolArena.java @@ -440,8 +440,7 @@ abstract class PoolArena implements PoolArenaMetric { private static List subPageMetricList(PoolSubpage[] pages) { List metrics = new ArrayList(); - for (int i = 0; i < pages.length; i ++) { - PoolSubpage head = pages[i]; + for (PoolSubpage head : pages) { if (head.next == head) { continue; } diff --git a/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java b/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java index 8fd3491fe0..73c8146493 100644 --- a/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java +++ b/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java @@ -448,8 +448,8 @@ public class PooledByteBufAllocator extends AbstractByteBufAllocator { } int total = 0; - for (int i = 0; i < arenas.length; i++) { - total += arenas[i].numThreadCaches.get(); + for (PoolArena arena : arenas) { + total += arena.numThreadCaches.get(); } return total; diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2Error.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2Error.java index d43e5a376d..9c8375eb0a 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2Error.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2Error.java @@ -42,8 +42,7 @@ public enum Http2Error { static { Http2Error[] errors = Http2Error.values(); Http2Error[] map = new Http2Error[errors.length]; - for (int i = 0; i < errors.length; ++i) { - Http2Error error = errors[i]; + for (Http2Error error : errors) { map[(int) error.code()] = error; } INT_TO_ENUM_MAP = map; diff --git a/codec/src/main/java/io/netty/handler/codec/compression/Bzip2BlockCompressor.java b/codec/src/main/java/io/netty/handler/codec/compression/Bzip2BlockCompressor.java index 7b5efb277c..de6307f084 100644 --- a/codec/src/main/java/io/netty/handler/codec/compression/Bzip2BlockCompressor.java +++ b/codec/src/main/java/io/netty/handler/codec/compression/Bzip2BlockCompressor.java @@ -117,8 +117,8 @@ final class Bzip2BlockCompressor { } } - for (int i = 0; i < condensedInUse.length; i++) { - writer.writeBoolean(out, condensedInUse[i]); + for (boolean isCondensedInUse : condensedInUse) { + writer.writeBoolean(out, isCondensedInUse); } for (int i = 0; i < condensedInUse.length; i++) { diff --git a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java index 40a07d45f4..76046c53b4 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java +++ b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java @@ -893,11 +893,11 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH */ private boolean ignoreException(Throwable t) { if (!(t instanceof SSLException) && t instanceof IOException && sslClosePromise.isDone()) { - String message = String.valueOf(t.getMessage()).toLowerCase(); + String message = t.getMessage(); // first try to match connection reset / broke peer based on the regex. This is the fastest way // but may fail on different jdk impls or OS's - if (IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) { + if (message != null && IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) { return true; } diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/IovArray.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/IovArray.java index 6f6736ac52..e7ff07dce8 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/IovArray.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/IovArray.java @@ -134,8 +134,7 @@ final class IovArray implements MessageProcessor { // No more room! return false; } - for (int i = 0; i < buffers.length; i++) { - ByteBuffer nioBuffer = buffers[i]; + for (ByteBuffer nioBuffer : buffers) { int offset = nioBuffer.position(); int len = nioBuffer.limit() - nioBuffer.position(); if (len == 0) { diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/NativeDatagramPacketArray.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/NativeDatagramPacketArray.java index 33f4eb8c8e..374f8a74ab 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/NativeDatagramPacketArray.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/NativeDatagramPacketArray.java @@ -39,10 +39,10 @@ final class NativeDatagramPacketArray implements ChannelOutboundBuffer.MessagePr @Override protected void onRemoval(NativeDatagramPacketArray value) throws Exception { - NativeDatagramPacket[] array = value.packets; + NativeDatagramPacket[] packetsArray = value.packets; // Release all packets - for (int i = 0; i < array.length; i++) { - array[i].release(); + for (NativeDatagramPacket datagramPacket : packetsArray) { + datagramPacket.release(); } } };