refac: использованы generics
This commit is contained in:
@@ -3,74 +3,63 @@ package ru.di9.minecraft.shared.utils;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@SuppressWarnings("ALL")
|
@SuppressWarnings("GrazieInspection")
|
||||||
public class IntCache
|
public class IntCache {
|
||||||
{
|
|
||||||
private static int intCacheSize = 256;
|
private static int intCacheSize = 256;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of pre-allocated int[256] arrays that are currently unused and can be returned by getIntCache()
|
* A list of pre-allocated int[256] arrays that are currently unused and can be returned by getIntCache()
|
||||||
*/
|
*/
|
||||||
private static List freeSmallArrays = new ArrayList();
|
private static final List<int[]> freeSmallArrays = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of pre-allocated int[256] arrays that were previously returned by getIntCache() and which will not be re-
|
* A list of pre-allocated int[256] arrays that were previously returned by getIntCache() and which will not be re-
|
||||||
* used again until resetIntCache() is called.
|
* used again until resetIntCache() is called.
|
||||||
*/
|
*/
|
||||||
private static List inUseSmallArrays = new ArrayList();
|
private static final List<int[]> inUseSmallArrays = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of pre-allocated int[cacheSize] arrays that are currently unused and can be returned by getIntCache()
|
* A list of pre-allocated int[cacheSize] arrays that are currently unused and can be returned by getIntCache()
|
||||||
*/
|
*/
|
||||||
private static List freeLargeArrays = new ArrayList();
|
private static final List<int[]> freeLargeArrays = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of pre-allocated int[cacheSize] arrays that were previously returned by getIntCache() and which will not
|
* A list of pre-allocated int[cacheSize] arrays that were previously returned by getIntCache() and which will not
|
||||||
* be re-used again until resetIntCache() is called.
|
* be re-used again until resetIntCache() is called.
|
||||||
*/
|
*/
|
||||||
private static List inUseLargeArrays = new ArrayList();
|
private static final List<int[]> inUseLargeArrays = new ArrayList<>();
|
||||||
|
|
||||||
public IntCache()
|
private IntCache() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[] getIntCache(int par0)
|
public static int[] getIntCache(int par0) {
|
||||||
{
|
if (par0 <= 256) {
|
||||||
if (par0 <= 256)
|
if (freeSmallArrays.isEmpty()) {
|
||||||
{
|
int[] ai = new int[256];
|
||||||
if (freeSmallArrays.size() == 0)
|
|
||||||
{
|
|
||||||
int ai[] = new int[256];
|
|
||||||
inUseSmallArrays.add(ai);
|
inUseSmallArrays.add(ai);
|
||||||
return ai;
|
return ai;
|
||||||
}
|
} else {
|
||||||
else
|
int[] ai1 = freeSmallArrays.remove(freeSmallArrays.size() - 1);
|
||||||
{
|
|
||||||
int ai1[] = (int[])freeSmallArrays.remove(freeSmallArrays.size() - 1);
|
|
||||||
inUseSmallArrays.add(ai1);
|
inUseSmallArrays.add(ai1);
|
||||||
return ai1;
|
return ai1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (par0 > intCacheSize)
|
if (par0 > intCacheSize) {
|
||||||
{
|
|
||||||
intCacheSize = par0;
|
intCacheSize = par0;
|
||||||
freeLargeArrays.clear();
|
freeLargeArrays.clear();
|
||||||
inUseLargeArrays.clear();
|
inUseLargeArrays.clear();
|
||||||
int ai2[] = new int[intCacheSize];
|
int[] ai2 = new int[intCacheSize];
|
||||||
inUseLargeArrays.add(ai2);
|
inUseLargeArrays.add(ai2);
|
||||||
return ai2;
|
return ai2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (freeLargeArrays.size() == 0)
|
if (freeLargeArrays.isEmpty()) {
|
||||||
{
|
int[] ai3 = new int[intCacheSize];
|
||||||
int ai3[] = new int[intCacheSize];
|
|
||||||
inUseLargeArrays.add(ai3);
|
inUseLargeArrays.add(ai3);
|
||||||
return ai3;
|
return ai3;
|
||||||
}
|
} else {
|
||||||
else
|
int[] ai4 = freeLargeArrays.remove(freeLargeArrays.size() - 1);
|
||||||
{
|
|
||||||
int ai4[] = (int[])freeLargeArrays.remove(freeLargeArrays.size() - 1);
|
|
||||||
inUseLargeArrays.add(ai4);
|
inUseLargeArrays.add(ai4);
|
||||||
return ai4;
|
return ai4;
|
||||||
}
|
}
|
||||||
@@ -79,15 +68,12 @@ public class IntCache
|
|||||||
/**
|
/**
|
||||||
* Mark all pre-allocated arrays as available for re-use by moving them to the appropriate free lists.
|
* Mark all pre-allocated arrays as available for re-use by moving them to the appropriate free lists.
|
||||||
*/
|
*/
|
||||||
public static void resetIntCache()
|
public static void resetIntCache() {
|
||||||
{
|
if (!freeLargeArrays.isEmpty()) {
|
||||||
if (freeLargeArrays.size() > 0)
|
|
||||||
{
|
|
||||||
freeLargeArrays.remove(freeLargeArrays.size() - 1);
|
freeLargeArrays.remove(freeLargeArrays.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (freeSmallArrays.size() > 0)
|
if (!freeSmallArrays.isEmpty()) {
|
||||||
{
|
|
||||||
freeSmallArrays.remove(freeSmallArrays.size() - 1);
|
freeSmallArrays.remove(freeSmallArrays.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user