Skip to content

Commit 35d8e8b

Browse files
Slightly improve performance
"setLore(Arrays.asList(...))" and "setLore(...)" are colorized methods the loop has been optimized by caching the size of the initial lore array list size and using a regular for loop. also now using the size on the for loop and the size for the ArrayList in the actual method.
1 parent b62c724 commit 35d8e8b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/main/java/me/flame/menus/items/ItemEditor.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ public ItemEditor setLore(String... lore) {
6767
* @param lore the new lore of the itemStack
6868
* @return the builder for chaining
6969
*/
70+
@SuppressWarnings("ForLoopReplaceableByForEach") // slight performance improvement
7071
public ItemEditor setLore(List<String> lore) {
71-
List<String> ogLore = new ArrayList<>(lore.size());
72-
for (String loreLine : lore)
73-
ogLore.add(translateAlternateColorCodes('&', loreLine));
72+
int loreSize = lore.size();
73+
List<String> ogLore = new ArrayList<>(loreSize);
74+
for (int i = 0; i < loreSize; i++)
75+
ogLore.add(translateAlternateColorCodes('&', lore.get(i)));
7476
this.meta.setLore(ogLore);
7577
return this;
7678
}
@@ -96,7 +98,7 @@ public ItemEditor setLore(boolean colorized, String... lore) {
9698
* @return the builder for chaining
9799
*/
98100
public ItemEditor setLore(boolean colorized, List<String> lore) {
99-
if (colorized) return this.setLore(lore);
101+
if (!colorized) return this.setLore(lore);
100102
this.meta.setLore(lore);
101103
return this;
102104
}

0 commit comments

Comments
 (0)