Skip to content

Commit fcc0df7

Browse files
perf(render): back wall slots with a fixed array (#87)
Co-authored-by: Arbousier1 <elderli@foxmail.com>
1 parent 3a5fb9b commit fcc0df7

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

src/main/java/top/ellan/mahjong/render/layout/TableRenderLayout.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import top.ellan.mahjong.render.snapshot.TableRenderSnapshot;
99
import top.ellan.mahjong.render.snapshot.TableSeatRenderSnapshot;
1010
import java.util.ArrayList;
11+
import java.util.Arrays;
1112
import java.util.Collections;
1213
import java.util.EnumMap;
1314
import java.util.List;
@@ -195,11 +196,8 @@ private static List<TilePlacement> precomputeWall(Point displayCenter, TableRend
195196
}
196197

197198
List<DeadWallPlacement> deadWallPlacements = deadWallPlacements(displayCenter, snapshot);
198-
List<TilePlacement> placements = new ArrayList<>(TOTAL_WALL_TILES);
199+
List<TilePlacement> placements = Arrays.asList(new TilePlacement[TOTAL_WALL_TILES]);
199200
boolean[] occupiedSlots = new boolean[TOTAL_WALL_TILES];
200-
for (int i = 0; i < TOTAL_WALL_TILES; i++) {
201-
placements.add(null);
202-
}
203201
int breakTileIndex = wallBreakTileIndex(snapshot);
204202
int firstLiveWallSlot = Math.floorMod(breakTileIndex + frontDrawCount, TOTAL_WALL_TILES);
205203
int wallSlot = firstLiveWallSlot;
@@ -229,7 +227,7 @@ private static List<TilePlacement> precomputeWall(Point displayCenter, TableRend
229227
Point point = settledWallPoint(placement.point(), placement.wallSlot(), occupiedSlots, WALL_TILES_PER_SIDE);
230228
placements.set(placement.wallSlot(), new TilePlacement(point, placement.yaw(), MahjongTile.UNKNOWN, DisplayEntities.TileRenderPose.FLAT_FACE_DOWN));
231229
}
232-
return Collections.unmodifiableList(new ArrayList<>(placements));
230+
return Collections.unmodifiableList(placements);
233231
}
234232

235233
private static List<TilePlacement> precomputeLiveWallWithoutDeadWall(Point displayCenter, TableRenderSnapshot snapshot) {
@@ -242,11 +240,8 @@ private static List<TilePlacement> precomputeLiveWallWithoutDeadWall(Point displ
242240
);
243241
int frontDrawCount = wallCapacity - remainingWallCount - supplementDrawCount;
244242
int breakTileIndex = wallBreakTileIndex(snapshot);
245-
List<TilePlacement> placements = new ArrayList<>(wallCapacity);
243+
List<TilePlacement> placements = Arrays.asList(new TilePlacement[wallCapacity]);
246244
boolean[] occupiedSlots = new boolean[wallCapacity];
247-
for (int i = 0; i < wallCapacity; i++) {
248-
placements.add(null);
249-
}
250245
int firstLiveWallSlot = Math.floorMod(breakTileIndex + frontDrawCount, wallCapacity);
251246
int wallSlot = firstLiveWallSlot;
252247
for (int i = 0; i < remainingWallCount; i++) {
@@ -261,7 +256,7 @@ private static List<TilePlacement> precomputeLiveWallWithoutDeadWall(Point displ
261256
placements.set(wallSlot, new TilePlacement(point, seatYaw(wind), MahjongTile.UNKNOWN, DisplayEntities.TileRenderPose.FLAT_FACE_DOWN));
262257
wallSlot = nextWallSlot(wallSlot, wallCapacity);
263258
}
264-
return Collections.unmodifiableList(new ArrayList<>(placements));
259+
return Collections.unmodifiableList(placements);
265260
}
266261

267262
private static int exposedFlowerCount(TableRenderSnapshot snapshot) {

0 commit comments

Comments
 (0)