Skip to content

Commit f322ec8

Browse files
Replace iterator.remove with more efficient removal, and other refactors (#5751)
1 parent ffe3708 commit f322ec8

14 files changed

Lines changed: 59 additions & 57 deletions

File tree

‎src/main/java/meteordevelopment/meteorclient/gui/GuiThemes.java‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import java.io.File;
1616
import java.io.IOException;
1717
import java.util.ArrayList;
18-
import java.util.Iterator;
1918
import java.util.List;
19+
import java.util.ListIterator;
2020

2121
public class GuiThemes {
2222
private static final File FOLDER = new File(MeteorClient.FOLDER, "gui");
@@ -50,12 +50,13 @@ public static void postInit() {
5050
}
5151

5252
public static void add(GuiTheme theme) {
53-
for (Iterator<GuiTheme> it = themes.iterator(); it.hasNext();) {
53+
for (ListIterator<GuiTheme> it = themes.listIterator(); it.hasNext();) {
5454
if (it.next().name.equals(theme.name)) {
55-
it.remove();
55+
// Replace the old one with same name
56+
it.set(theme);
5657

5758
MeteorClient.LOG.error("Theme with the name '{}' has already been added.", theme.name);
58-
break;
59+
return;
5960
}
6061
}
6162

‎src/main/java/meteordevelopment/meteorclient/systems/modules/combat/ArrowDodge.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public ArrowDodge() {
111111

112112
@EventHandler
113113
private void onTick(TickEvent.Pre event) {
114-
for (Vector3d point : points) vec3s.free(point);
114+
vec3s.freeAll(points);
115115
points.clear();
116116

117117
for (Entity e : mc.world.getEntities()) {

‎src/main/java/meteordevelopment/meteorclient/systems/modules/render/Breadcrumbs.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void onActivate() {
6767

6868
@Override
6969
public void onDeactivate() {
70-
for (Section section : sections) sectionPool.free(section);
70+
sectionPool.freeAll(sections);
7171
sections.clear();
7272
}
7373

@@ -76,7 +76,7 @@ private void onTick(TickEvent.Post event) {
7676
if (!mc.player.isLoaded()) return;
7777

7878
if (lastDimension != mc.world.getDimension()) {
79-
for (Section sec : sections) sectionPool.free(sec);
79+
sectionPool.freeAll(sections);
8080
sections.clear();
8181
}
8282

‎src/main/java/meteordevelopment/meteorclient/systems/modules/render/HoleESP.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public HoleESP() {
168168

169169
@EventHandler
170170
private void onTick(TickEvent.Pre event) {
171-
for (Hole hole : holes) holePool.free(hole);
171+
holePool.freeAll(holes);
172172
holes.clear();
173173

174174
// Probe for holes

‎src/main/java/meteordevelopment/meteorclient/systems/modules/render/LightOverlay.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public LightOverlay() {
8585

8686
@EventHandler
8787
private void onTick(TickEvent.Pre event) {
88-
for (Cross cross : crosses) crossPool.free(cross);
88+
crossPool.freeAll(crosses);
8989
crosses.clear();
9090

9191
BlockIterator.register(horizontalRange.get(), verticalRange.get(), (blockPos, blockState) -> {

‎src/main/java/meteordevelopment/meteorclient/systems/modules/render/Trajectories.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ private class Path {
230230
public Vector3d lastPoint;
231231

232232
public void clear() {
233-
for (Vector3d point : points) vec3s.free(point);
233+
vec3s.freeAll(points);
234234
points.clear();
235235

236236
hitQuad = false;

‎src/main/java/meteordevelopment/meteorclient/systems/modules/world/PacketMine.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void onActivate() {
136136

137137
@Override
138138
public void onDeactivate() {
139-
for (MyBlock block : blocks) blockPool.free(block);
139+
blockPool.freeAll(blocks);
140140
blocks.clear();
141141

142142
if (shouldUpdateSlot) {

‎src/main/java/meteordevelopment/meteorclient/systems/modules/world/SpawnProofer.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private void onTickPre(TickEvent.Pre event) {
115115
}
116116

117117
// Find spawn locations
118-
for (BlockPos.Mutable blockPos : spawns) spawnPool.free(blockPos);
118+
spawnPool.freeAll(spawns);
119119
spawns.clear();
120120

121121
BlockIterator.register((int) Math.ceil(placeRange.get()), (int) Math.ceil(placeRange.get()), (blockPos, blockState) -> {

‎src/main/java/meteordevelopment/meteorclient/systems/modules/world/VeinMiner.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public VeinMiner() {
140140

141141
@Override
142142
public void onDeactivate() {
143-
for (MyBlock block : blocks) blockPool.free(block);
143+
blockPool.freeAll(blocks);
144144
blocks.clear();
145145
foundBlockPositions.clear();
146146
}

‎src/main/java/meteordevelopment/meteorclient/systems/waypoints/Waypoints.java‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import net.minecraft.client.texture.NativeImageBackedTexture;
2525
import net.minecraft.nbt.NbtCompound;
2626
import net.minecraft.nbt.NbtElement;
27+
import org.apache.commons.lang3.StringUtils;
2728
import org.jetbrains.annotations.NotNull;
2829

2930
import java.io.File;
@@ -32,13 +33,16 @@
3233
import java.io.InputStream;
3334
import java.util.*;
3435
import java.util.concurrent.ConcurrentHashMap;
36+
import java.util.concurrent.CopyOnWriteArrayList;
3537

3638
public class Waypoints extends System<Waypoints> implements Iterable<Waypoint> {
39+
private static final String PNG = ".png";
40+
3741
public static final String[] BUILTIN_ICONS = {"square", "circle", "triangle", "star", "diamond", "skull"};
3842

3943
public final Map<String, AbstractTexture> icons = new ConcurrentHashMap<>();
4044

41-
private final List<Waypoint> waypoints = Collections.synchronizedList(new ArrayList<>());
45+
private final List<Waypoint> waypoints = new CopyOnWriteArrayList<>();
4246

4347
public Waypoints() {
4448
super(null);
@@ -54,18 +58,18 @@ public void init() {
5458
iconsFolder.mkdirs();
5559

5660
for (String builtinIcon : BUILTIN_ICONS) {
57-
File iconFile = new File(iconsFolder, builtinIcon + ".png");
61+
File iconFile = new File(iconsFolder, builtinIcon + PNG);
5862
if (!iconFile.exists()) copyIcon(iconFile);
5963
}
6064

6165
File[] files = iconsFolder.listFiles();
6266
if (files == null) return;
6367

6468
for (File file : files) {
65-
if (file.getName().endsWith(".png")) {
66-
try {
67-
String name = file.getName().replace(".png", "");
68-
AbstractTexture texture = new NativeImageBackedTexture(null, NativeImage.read(new FileInputStream(file)));
69+
if (file.getName().endsWith(PNG)) {
70+
try (FileInputStream inputStream = new FileInputStream(file)) {
71+
String name = StringUtils.removeEnd(file.getName(), PNG);
72+
AbstractTexture texture = new NativeImageBackedTexture(() -> name, NativeImage.read(inputStream));
6973
icons.put(name, texture);
7074
}
7175
catch (IOException e) {

0 commit comments

Comments
 (0)