From a8950dfc4cd0f0acc9900e315b98f518c3694e8f Mon Sep 17 00:00:00 2001 From: Max Zhuravkov Date: Tue, 3 Jan 2017 13:25:33 +0300 Subject: [PATCH] InternalThreadLocalMap.arrayList should create a reusable ArrayList only if arrayList field is NULL. Motivation: InternalThreadLocalMap.arrayList returns a new ArrayList every time it's called that defeats the purpose of having a reusable ArrayList. Modification: Modified InternalThreadLocalMap.arrayList to create an ArrayList only if arrayList field is NULL. Result: InternalThreadLocalMap.arrayList now creates a reusable ArrayList only if arrayList field is NULL. --- .../io/netty/util/internal/InternalThreadLocalMap.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/io/netty/util/internal/InternalThreadLocalMap.java b/common/src/main/java/io/netty/util/internal/InternalThreadLocalMap.java index 25bf537556..7d2a71d56e 100644 --- a/common/src/main/java/io/netty/util/internal/InternalThreadLocalMap.java +++ b/common/src/main/java/io/netty/util/internal/InternalThreadLocalMap.java @@ -192,14 +192,15 @@ public final class InternalThreadLocalMap extends UnpaddedInternalThreadLocalMap return arrayList(DEFAULT_ARRAY_LIST_INITIAL_CAPACITY); } + @SuppressWarnings("unchecked") public ArrayList arrayList(int minCapacity) { ArrayList list = (ArrayList) arrayList; if (list == null) { - list = (ArrayList) new ArrayList(minCapacity); - } else { - list.clear(); - list.ensureCapacity(minCapacity); + arrayList = new ArrayList(minCapacity); + return (ArrayList) arrayList; } + list.clear(); + list.ensureCapacity(minCapacity); return list; }