Skip to content

Commit 1c21918

Browse files
Improve performance.
1 parent ebdbb29 commit 1c21918

File tree

1 file changed

+9
-31
lines changed

1 file changed

+9
-31
lines changed

src/main/java/me/flame/menus/menu/IterationDirection.java

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public Slot shift(Slot oldPos, int maxRows) {
3636
oldRow++;
3737
}
3838

39-
return new Slot(oldRow, oldCol);
39+
return oldPos.setSlot(oldRow, oldCol);
4040
}
4141
},
4242

@@ -58,73 +58,51 @@ public Slot shift(Slot oldPos, int maxRows) {
5858
@Override
5959
public Slot shift(Slot oldPos, int maxRows) {
6060
int col = oldPos.col + 1;
61-
if (col > 9) {
62-
return Slot.NaS;
63-
}
64-
return new Slot(oldPos.row, col);
61+
return col > 9 ? Slot.NaS : oldPos.setSlot(oldPos.row, col);
6562
}
6663
},
6764

6865
LEFT_ONLY {
6966
@Override
7067
public Slot shift(Slot oldPos, int maxRows) {
7168
int col = oldPos.col - 1;
72-
if (col < 0) {
73-
return Slot.NaS;
74-
}
75-
return new Slot(oldPos.row, col);
69+
return col < 0 ? Slot.NaS : oldPos.setSlot(oldPos.row, col);
7670
}
7771
},
7872

7973
RIGHT_UPWARDS_ONLY {
8074
@Override
8175
public Slot shift(Slot oldPos, int maxRows) {
8276
Slot upwardSlot = UPWARDS_ONLY.shift(oldPos, maxRows);
83-
int row = upwardSlot.row;
84-
8577
Slot rightSlot = RIGHT_ONLY.shift(oldPos, maxRows);
86-
int col = rightSlot.col;
87-
88-
return new Slot(row, col);
78+
return oldPos.setSlot(upwardSlot.row, rightSlot.col);
8979
}
9080
},
9181

9282
RIGHT_DOWNWARDS_ONLY {
9383
@Override
9484
public Slot shift(Slot oldPos, int maxRows) {
9585
Slot downwardSlot = DOWNWARDS_ONLY.shift(oldPos, maxRows);
96-
int row = downwardSlot.row;
97-
9886
Slot rightSlot = RIGHT_ONLY.shift(oldPos, maxRows);
99-
int col = rightSlot.col;
100-
101-
return new Slot(row, col);
87+
return oldPos.setSlot(downwardSlot.row, rightSlot.col);
10288
}
10389
},
10490

10591
LEFT_UPWARDS {
10692
@Override
10793
public Slot shift(Slot oldPos, int maxRows) {
10894
Slot upwardSlot = UPWARDS_ONLY.shift(oldPos, maxRows);
109-
int row = upwardSlot.row;
110-
11195
Slot leftSlot = LEFT_ONLY.shift(oldPos, maxRows);
112-
int col = leftSlot.col;
113-
114-
return new Slot(row, col);
96+
return oldPos.setSlot(upwardSlot.row, leftSlot.col);
11597
}
11698
},
11799

118100
LEFT_DOWNWARDS {
119101
@Override
120102
public Slot shift(Slot oldPos, int maxRows) {
121103
Slot downwardSlot = DOWNWARDS_ONLY.shift(oldPos, maxRows);
122-
int row = downwardSlot.row;
123-
124104
Slot leftSlot = LEFT_ONLY.shift(oldPos, maxRows);
125-
int col = leftSlot.col;
126-
127-
return new Slot(row, col);
105+
return oldPos.setSlot(downwardSlot.row, leftSlot.col);
128106
}
129107
},
130108

@@ -141,7 +119,7 @@ public Slot shift(Slot oldPos, int maxRows) {
141119
oldCol--;
142120
}
143121

144-
return new Slot(oldRow, oldCol);
122+
return oldPos.setSlot(oldRow, oldCol);
145123
}
146124
},
147125

@@ -158,7 +136,7 @@ public Slot shift(Slot oldPos, int maxRows) {
158136
oldRow--;
159137
}
160138

161-
return new Slot(oldRow, oldCol);
139+
return oldPos.setSlot(oldRow, oldCol);
162140
}
163141
};
164142

0 commit comments

Comments
 (0)