optimize StructureDefinition.addShape (#54)

Before: 161ms of loading time
After: 60.7ms of loading time

An example with Forge of Gods
<img width="1917" height="513" alt="image"
src="https://github.com/user-attachments/assets/61e9b420-7cc2-4e76-89f3-864bd6d7a77f"
/>
<img width="1918" height="490" alt="image"
src="https://github.com/user-attachments/assets/5297956c-41c8-43f7-9451-e29e26609a7e"
/>
This commit is contained in:
danyadev authored and GitHub committed 2026-03-01 13:03:05 +01:00
1 parent 0866dbee98
commit e774dd5e10
1 file changed
+21 -4
@@ -148,15 +148,32 @@ public class StructureDefinition<T> implements IStructureDefinition<T> {
occupiedSpaces.put(name, occupiedSpace);
String built = builder.toString().replaceAll("[\\uA000\\uB000\\uC000]", "");
boolean hasPlus = false;
boolean hasMinus = false;
if (built.contains("+")) {
int write = 0;
for (int read = 0; read < builder.length(); read++) {
char ch = builder.charAt(read);
if (ch == A || ch == B || ch == C) {
continue;
}
if (ch == '+') {
hasPlus = true;
} else if (ch == '-') {
hasMinus = true;
}
if (read != write) builder.setCharAt(write, ch);
write++;
}
builder.setLength(write);
if (hasPlus) {
addElement('+', notAir());
}
if (built.contains("-")) {
if (hasMinus) {
addElement('-', isAir());
}
shapes.put(name, built);
shapes.put(name, builder.toString());
return this;
}