Skip to content

Commit

Permalink
InternalThreadLocalMap.arrayList should create a reusable ArrayList o…
Browse files Browse the repository at this point in the history
…nly 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.
  • Loading branch information
lowka authored and Scottmitch committed Jan 3, 2017
1 parent 68a941c commit a8950df
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,15 @@ public <E> ArrayList<E> arrayList() {
return arrayList(DEFAULT_ARRAY_LIST_INITIAL_CAPACITY);
}

@SuppressWarnings("unchecked")
public <E> ArrayList<E> arrayList(int minCapacity) {
ArrayList<E> list = (ArrayList<E>) arrayList;
if (list == null) {
list = (ArrayList<E>) new ArrayList<Object>(minCapacity);
} else {
list.clear();
list.ensureCapacity(minCapacity);
arrayList = new ArrayList<Object>(minCapacity);
return (ArrayList<E>) arrayList;
}
list.clear();
list.ensureCapacity(minCapacity);
return list;
}

Expand Down

0 comments on commit a8950df

Please sign in to comment.