80,349
社区成员
发帖
与我相关
我的任务
分享
static final class VacantCell {
int cellX;
int cellY;
int spanX;
int spanY;
// We can create up to 523 vacant cells on a 4x4 grid, 100 seems
// like a reasonable compromise given the size of a VacantCell and
// the fact that the user is not likely to touch an empty 4x4 grid
// very often
private static final int POOL_LIMIT = 100;
private static final Object sLock = new Object();
private static int sAcquiredCount = 0;
private static VacantCell sRoot;
private VacantCell next;
static VacantCell acquire() {
synchronized (sLock) {
if (sRoot == null) {
return new VacantCell();
}
VacantCell info = sRoot;
sRoot = info.next;
sAcquiredCount--;
return info;
}
}
void release() {
synchronized (sLock) {
if (sAcquiredCount < POOL_LIMIT) {
sAcquiredCount++;
next = sRoot;
sRoot = this;
}
}
}
@Override
public String toString() {
return "VacantCell[x=" + cellX + ", y=" + cellY + ", spanX=" + spanX +
", spanY=" + spanY + "]";
}
}