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.
This commit is contained in:
Max Zhuravkov 2017-01-03 13:25:33 +03:00 committed by Scott Mitchell
parent 68a941c091
commit a8950dfc4c

View File

@ -192,14 +192,15 @@ public final class InternalThreadLocalMap extends UnpaddedInternalThreadLocalMap
return arrayList(DEFAULT_ARRAY_LIST_INITIAL_CAPACITY); return arrayList(DEFAULT_ARRAY_LIST_INITIAL_CAPACITY);
} }
@SuppressWarnings("unchecked")
public <E> ArrayList<E> arrayList(int minCapacity) { public <E> ArrayList<E> arrayList(int minCapacity) {
ArrayList<E> list = (ArrayList<E>) arrayList; ArrayList<E> list = (ArrayList<E>) arrayList;
if (list == null) { if (list == null) {
list = (ArrayList<E>) new ArrayList<Object>(minCapacity); arrayList = new ArrayList<Object>(minCapacity);
} else { return (ArrayList<E>) arrayList;
}
list.clear(); list.clear();
list.ensureCapacity(minCapacity); list.ensureCapacity(minCapacity);
}
return list; return list;
} }