fill sentinal proeprly when its not in cache
This commit is contained in:
parent
a89aeb3a6d
commit
d845a306fa
|
@ -354,6 +354,7 @@ public class CacheRecycler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[] popIntArray(int size, int sentinal) {
|
public static int[] popIntArray(int size, int sentinal) {
|
||||||
|
size = size < 100 ? 100 : size;
|
||||||
SoftReference<Deque<int[]>> ref = intArray.get();
|
SoftReference<Deque<int[]>> ref = intArray.get();
|
||||||
Deque<int[]> deque = ref == null ? null : ref.get();
|
Deque<int[]> deque = ref == null ? null : ref.get();
|
||||||
if (deque == null) {
|
if (deque == null) {
|
||||||
|
@ -361,11 +362,19 @@ public class CacheRecycler {
|
||||||
intArray.set(new SoftReference<Deque<int[]>>(deque));
|
intArray.set(new SoftReference<Deque<int[]>>(deque));
|
||||||
}
|
}
|
||||||
if (deque.isEmpty()) {
|
if (deque.isEmpty()) {
|
||||||
return new int[size];
|
int[] ints = new int[size];
|
||||||
|
if (sentinal != 0) {
|
||||||
|
Arrays.fill(ints, sentinal);
|
||||||
|
}
|
||||||
|
return ints;
|
||||||
}
|
}
|
||||||
int[] ints = deque.pollFirst();
|
int[] ints = deque.pollFirst();
|
||||||
if (ints.length < size) {
|
if (ints.length < size) {
|
||||||
return new int[size];
|
ints = new int[size];
|
||||||
|
if (sentinal != 0) {
|
||||||
|
Arrays.fill(ints, sentinal);
|
||||||
|
}
|
||||||
|
return ints;
|
||||||
}
|
}
|
||||||
Arrays.fill(ints, sentinal);
|
Arrays.fill(ints, sentinal);
|
||||||
return ints;
|
return ints;
|
||||||
|
|
Loading…
Reference in New Issue