mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-01 00:06:47 +00:00
Making code more readable by removing global variable used for optimizations
Using the stack was more efficient because it prevented the creation of new rectangles but it makes the code harder to read and prone to bugs if the global state of the stack of rectangles gets corrupted in any way. When this optimization was written in 2008 it was necessary but now I don't think it would have a big impact. The stack size is on average of 30 and the rectangles are only created when doing the reorder which runs about once per second if the user moves the finger too quickly. Bug: 188081026 Test: atest ReorderWidgets Change-Id: I35d8ee8d92f01035e72fe5763a7de47f4b6a73de
This commit is contained in:
committed by
Sebastián Franco
parent
ef24d5954c
commit
4a92267d1d
@@ -402,7 +402,6 @@ public class CellLayout extends ViewGroup {
|
||||
mCountY = y;
|
||||
mOccupied = new GridOccupancy(mCountX, mCountY);
|
||||
mTmpOccupied = new GridOccupancy(mCountX, mCountY);
|
||||
mTempRectStack.clear();
|
||||
mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mCountX, mCountY,
|
||||
mBorderSpace);
|
||||
requestLayout();
|
||||
@@ -1247,21 +1246,6 @@ public class CellLayout extends ViewGroup {
|
||||
result, resultSpan);
|
||||
}
|
||||
|
||||
private final Stack<Rect> mTempRectStack = new Stack<>();
|
||||
private void lazyInitTempRectStack() {
|
||||
if (mTempRectStack.isEmpty()) {
|
||||
for (int i = 0; i < mCountX * mCountY; i++) {
|
||||
mTempRectStack.push(new Rect());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void recycleTempRects(Stack<Rect> used) {
|
||||
while (!used.isEmpty()) {
|
||||
mTempRectStack.push(used.pop());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a vacant area that will fit the given bounds nearest the requested
|
||||
* cell location. Uses Euclidean distance to score multiple vacant areas.
|
||||
@@ -1281,8 +1265,6 @@ public class CellLayout extends ViewGroup {
|
||||
*/
|
||||
private int[] findNearestArea(int relativeXPos, int relativeYPos, int minSpanX, int minSpanY,
|
||||
int spanX, int spanY, boolean ignoreOccupied, int[] result, int[] resultSpan) {
|
||||
lazyInitTempRectStack();
|
||||
|
||||
// For items with a spanX / spanY > 1, the passed in point (relativeXPos, relativeYPos)
|
||||
// corresponds to the center of the item, but we are searching based on the top-left cell,
|
||||
// so we translate the point over to correspond to the top-left.
|
||||
@@ -1352,9 +1334,6 @@ public class CellLayout extends ViewGroup {
|
||||
hitMaxY |= ySize >= spanY;
|
||||
incX = !incX;
|
||||
}
|
||||
incX = true;
|
||||
hitMaxX = xSize >= spanX;
|
||||
hitMaxY = ySize >= spanY;
|
||||
}
|
||||
final int[] cellXY = mTmpPoint;
|
||||
cellToCenterPoint(x, y, cellXY);
|
||||
@@ -1362,8 +1341,7 @@ public class CellLayout extends ViewGroup {
|
||||
// We verify that the current rect is not a sub-rect of any of our previous
|
||||
// candidates. In this case, the current rect is disqualified in favour of the
|
||||
// containing rect.
|
||||
Rect currentRect = mTempRectStack.pop();
|
||||
currentRect.set(x, y, x + xSize, y + ySize);
|
||||
Rect currentRect = new Rect(x, y, x + xSize, y + ySize);
|
||||
boolean contained = false;
|
||||
for (Rect r : validRegions) {
|
||||
if (r.contains(currentRect)) {
|
||||
@@ -1393,7 +1371,6 @@ public class CellLayout extends ViewGroup {
|
||||
bestXY[0] = -1;
|
||||
bestXY[1] = -1;
|
||||
}
|
||||
recycleTempRects(validRegions);
|
||||
return bestXY;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user