Merge pull request #15 from cyberpwnn/performance-passes

Performance passes
This commit is contained in:
Dan 2020-10-16 01:57:47 -04:00 committed by GitHub
commit e530e30878
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 91 additions and 97 deletions

View File

@ -36,9 +36,9 @@ public class CommandIrisDownload extends MortarCommand
for(String i : args) for(String i : args)
{ {
if(i.equals("-t") || i.equals("--trim")) if (i.equals("-t") || i.equals("--trim")) {
{
trim = true; trim = true;
break;
} }
} }

View File

@ -48,9 +48,9 @@ public class CommandIrisObjectPaste extends MortarCommand
for(String i : args) for(String i : args)
{ {
if(i.equalsIgnoreCase("-edit")) if (i.equalsIgnoreCase("-edit")) {
{
intoWand = true; intoWand = true;
break;
} }
} }

View File

@ -51,9 +51,9 @@ public class CommandIrisObjectSave extends MortarCommand
for(String i : args) for(String i : args)
{ {
if(i.equals("-o")) if (i.equals("-o")) {
{
overwrite = true; overwrite = true;
break;
} }
} }

View File

@ -39,9 +39,9 @@ public class CommandIrisStructureCreate extends MortarCommand
for(String i : args) for(String i : args)
{ {
if(i.equalsIgnoreCase("-3d")) if (i.equalsIgnoreCase("-3d")) {
{
d3 = true; d3 = true;
break;
} }
} }

View File

@ -74,9 +74,9 @@ public class CommandIrisStudioGoto extends MortarCommand
for(String i : args) for(String i : args)
{ {
if(i.equalsIgnoreCase("-cave")) if (i.equalsIgnoreCase("-cave")) {
{
cave = true; cave = true;
break;
} }
} }

View File

@ -38,9 +38,9 @@ public class CommandIrisStudioPackage extends MortarCommand
for(String i : args) for(String i : args)
{ {
if(i.equalsIgnoreCase("-o")) if (i.equalsIgnoreCase("-o")) {
{
o = true; o = true;
break;
} }
} }

View File

@ -298,7 +298,7 @@ public class NoiseExplorer extends JPanel implements MouseWheelListener
NoiseExplorer nv = new NoiseExplorer(); NoiseExplorer nv = new NoiseExplorer();
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
KList<String> li = new KList<NoiseStyle>(NoiseStyle.values()).toStringList(); KList<String> li = new KList<NoiseStyle>(NoiseStyle.values()).toStringList();
combo = new JComboBox<String>(li.toArray(new String[li.size()])); combo = new JComboBox<String>(li.toArray(new String[0]));
combo.setSelectedItem("STATIC"); combo.setSelectedItem("STATIC");
combo.setFocusable(false); combo.setFocusable(false);
combo.addActionListener(new ActionListener() combo.addActionListener(new ActionListener()

View File

@ -47,7 +47,7 @@ public class MythicMobsLink
} }
} }
return v.toArray(new String[v.size()]); return v.toArray(new String[0]);
} }
public Plugin getMythicMobs() public Plugin getMythicMobs()

View File

@ -99,17 +99,17 @@ public class IrisDataManager
{ {
File examples = new File(dataFolder, "example"); File examples = new File(dataFolder, "example");
examples.mkdirs(); examples.mkdirs();
String biomes = ""; StringBuilder biomes = new StringBuilder();
String envs = ""; StringBuilder envs = new StringBuilder();
for(Biome i : Biome.values()) for(Biome i : Biome.values())
{ {
biomes += i.name() + "\n"; biomes.append(i.name()).append("\n");
} }
for(Environment i : Environment.values()) for(Environment i : Environment.values())
{ {
envs += i.name() + "\n"; envs.append(i.name()).append("\n");
} }
try try
@ -118,8 +118,8 @@ public class IrisDataManager
new File(examples, "example-pack/biomes").mkdirs(); new File(examples, "example-pack/biomes").mkdirs();
new File(examples, "example-pack/dimensions").mkdirs(); new File(examples, "example-pack/dimensions").mkdirs();
new File(examples, "example-pack/generators").mkdirs(); new File(examples, "example-pack/generators").mkdirs();
IO.writeAll(new File(examples, "biome-list.txt"), biomes); IO.writeAll(new File(examples, "biome-list.txt"), biomes.toString());
IO.writeAll(new File(examples, "environment-list.txt"), envs); IO.writeAll(new File(examples, "environment-list.txt"), envs.toString());
IrisGenerator gen = new IrisGenerator(); IrisGenerator gen = new IrisGenerator();
IrisNoiseGenerator n = new IrisNoiseGenerator(); IrisNoiseGenerator n = new IrisNoiseGenerator();

View File

@ -133,7 +133,7 @@ public class B
} }
} }
return bt.toArray(new String[bt.size()]); return bt.toArray(new String[0]);
} }
public static String[] getItemTypes() public static String[] getItemTypes()
@ -146,7 +146,7 @@ public class B
bt.add(v); bt.add(v);
} }
return bt.toArray(new String[bt.size()]); return bt.toArray(new String[0]);
} }
public static BlockData getBlockData(String bdxf, IrisDimension resolver) public static BlockData getBlockData(String bdxf, IrisDimension resolver)

View File

@ -753,7 +753,7 @@ public enum C
*/ */
public static String getLastColors(String input) public static String getLastColors(String input)
{ {
String result = ""; StringBuilder result = new StringBuilder();
int length = input.length(); int length = input.length();
// Search backwards from the end as it is faster // Search backwards from the end as it is faster
@ -767,7 +767,7 @@ public enum C
if(color != null) if(color != null)
{ {
result = color.toString() + result; result.insert(0, color.toString());
// Once we find a color or reset we can stop searching // Once we find a color or reset we can stop searching
if(color.isColor() || color.equals(RESET)) if(color.isColor() || color.equals(RESET))
@ -778,7 +778,7 @@ public enum C
} }
} }
return result; return result.toString();
} }
static static

View File

@ -72,9 +72,9 @@ public final class CompoundTag extends Tag {
append = "(\"" + this.getName() + "\")"; append = "(\"" + this.getName() + "\")";
} }
StringBuilder bldr = new StringBuilder(); StringBuilder bldr = new StringBuilder();
bldr.append("TAG_Compound" + append + ": " + value.size() + " entries\r\n{\r\n"); bldr.append("TAG_Compound").append(append).append(": ").append(value.size()).append(" entries\r\n{\r\n");
for (Map.Entry<String, Tag> entry : value.entrySet()) { for (Map.Entry<String, Tag> entry : value.entrySet()) {
bldr.append(" " + entry.getValue().toString().replaceAll("\r\n", "\r\n ") + "\r\n"); bldr.append(" ").append(entry.getValue().toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
} }
bldr.append("}"); bldr.append("}");
return bldr.toString(); return bldr.toString();

View File

@ -5,10 +5,7 @@ public class DoubleArrayUtils
{ {
public static void shiftRight(double[] values, double push) public static void shiftRight(double[] values, double push)
{ {
for(int index = values.length - 2; index >= 0; index--) if (values.length - 2 + 1 >= 0) System.arraycopy(values, 0, values, 1, values.length - 2 + 1);
{
values[index + 1] = values[index];
}
values[0] = push; values[0] = push;
} }

View File

@ -72,24 +72,24 @@ public class Form
*/ */
public static String capitalize(String s) public static String capitalize(String s)
{ {
String roll = ""; StringBuilder roll = new StringBuilder();
boolean f = true; boolean f = true;
for(Character i : s.trim().toCharArray()) for(Character i : s.trim().toCharArray())
{ {
if(f) if(f)
{ {
roll += Character.toUpperCase(i); roll.append(Character.toUpperCase(i));
f = false; f = false;
} }
else else
{ {
roll += i; roll.append(i);
} }
} }
return roll; return roll.toString();
} }
/** /**
@ -101,11 +101,11 @@ public class Form
*/ */
public static String capitalizeWords(String s) public static String capitalizeWords(String s)
{ {
String rollx = ""; StringBuilder rollx = new StringBuilder();
for(String i : s.trim().split(" ")) for(String i : s.trim().split(" "))
{ {
rollx += " " + capitalize(i.trim()); rollx.append(" ").append(capitalize(i.trim()));
} }
return rollx.substring(1); return rollx.substring(1);
@ -876,7 +876,7 @@ public class Form
*/ */
public static String ofSize(long s, int div) public static String ofSize(long s, int div)
{ {
Double d = (double) s; double d = (double) s;
String sub = "Bytes"; String sub = "Bytes";
if(d > div - 1) if(d > div - 1)
@ -929,7 +929,7 @@ public class Form
*/ */
public static String ofSize(long s, int div, int dec) public static String ofSize(long s, int div, int dec)
{ {
Double d = (double) s; double d = (double) s;
String sub = "Bytes"; String sub = "Bytes";
if(d > div - 1) if(d > div - 1)
@ -979,7 +979,7 @@ public class Form
{ {
s = -s; s = -s;
} }
Double d = (double) s; double d = (double) s;
String sub = "Grams"; String sub = "Grams";
if(d > div - 1) if(d > div - 1)
@ -1038,27 +1038,27 @@ public class Form
*/ */
public static String cname(String clazz) public static String cname(String clazz)
{ {
String codeName = ""; StringBuilder codeName = new StringBuilder();
for(Character i : clazz.toCharArray()) for(Character i : clazz.toCharArray())
{ {
if(Character.isUpperCase(i)) if(Character.isUpperCase(i))
{ {
codeName = codeName + "-" + Character.toLowerCase(i); codeName.append("-").append(Character.toLowerCase(i));
} }
else else
{ {
codeName = codeName + i; codeName.append(i);
} }
} }
if(codeName.startsWith("-")) if(codeName.toString().startsWith("-"))
{ {
codeName = codeName.substring(1); codeName = new StringBuilder(codeName.substring(1));
} }
return codeName; return codeName.toString();
} }
/** /**
@ -1439,17 +1439,17 @@ public class Form
roman_numerals.put("IV", 4); roman_numerals.put("IV", 4);
roman_numerals.put("I", 1); roman_numerals.put("I", 1);
String res = ""; StringBuilder res = new StringBuilder();
for(Map.Entry<String, Integer> entry : roman_numerals.entrySet()) for(Map.Entry<String, Integer> entry : roman_numerals.entrySet())
{ {
int matches = num / entry.getValue(); int matches = num / entry.getValue();
res += repeat(entry.getKey(), matches); res.append(repeat(entry.getKey(), matches));
num = num % entry.getValue(); num = num % entry.getValue();
} }
return res; return res.toString();
} }
/** /**

View File

@ -407,33 +407,33 @@ public class IO
public static String readAll(File f) throws IOException public static String readAll(File f) throws IOException
{ {
BufferedReader bu = new BufferedReader(new FileReader(f)); BufferedReader bu = new BufferedReader(new FileReader(f));
String c = ""; StringBuilder c = new StringBuilder();
String l = ""; String l = "";
while((l = bu.readLine()) != null) while((l = bu.readLine()) != null)
{ {
c += l + "\n"; c.append(l).append("\n");
} }
bu.close(); bu.close();
return c; return c.toString();
} }
public static String readAll(InputStream in) throws IOException public static String readAll(InputStream in) throws IOException
{ {
BufferedReader bu = new BufferedReader(new InputStreamReader(in)); BufferedReader bu = new BufferedReader(new InputStreamReader(in));
String c = ""; StringBuilder c = new StringBuilder();
String l = ""; String l = "";
while((l = bu.readLine()) != null) while((l = bu.readLine()) != null)
{ {
c += l + "\n"; c.append(l).append("\n");
} }
bu.close(); bu.close();
return c; return c.toString();
} }
/** /**

View File

@ -1652,7 +1652,7 @@ public class JSONObject
*/ */
public static Object stringToValue(String string) public static Object stringToValue(String string)
{ {
Double d; double d;
if(string.equals("")) if(string.equals(""))
{ {
return string; return string;
@ -1682,8 +1682,8 @@ public class JSONObject
{ {
if(string.indexOf('.') > -1 || string.indexOf('e') > -1 || string.indexOf('E') > -1) if(string.indexOf('.') > -1 || string.indexOf('e') > -1 || string.indexOf('E') > -1)
{ {
d = Double.valueOf(string); d = Double.parseDouble(string);
if(!d.isInfinite() && !d.isNaN()) if(!Double.isInfinite(d) && !Double.isNaN(d))
{ {
return d; return d;
} }

View File

@ -253,7 +253,7 @@ public class KList<T> extends ArrayList<T> implements List<T>
for(String i : toStringList()) for(String i : toStringList())
{ {
b.append(split + i); b.append(split).append(i);
} }
return b.toString().substring(split.length()); return b.toString().substring(split.length());
@ -382,10 +382,7 @@ public class KList<T> extends ArrayList<T> implements List<T>
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public KList<T> add(T... t) public KList<T> add(T... t)
{ {
for(T i : t) Collections.addAll(super, t);
{
super.add(i);
}
return this; return this;
} }

View File

@ -88,9 +88,9 @@ public final class ListTag extends Tag {
append = "(\"" + this.getName() + "\")"; append = "(\"" + this.getName() + "\")";
} }
StringBuilder bldr = new StringBuilder(); StringBuilder bldr = new StringBuilder();
bldr.append("TAG_List" + append + ": " + value.size() + " entries of type " + NBTUtils.getTypeName(type) + "\r\n{\r\n"); bldr.append("TAG_List").append(append).append(": ").append(value.size()).append(" entries of type ").append(NBTUtils.getTypeName(type)).append("\r\n{\r\n");
for (Tag t : value) { for (Tag t : value) {
bldr.append(" " + t.toString().replaceAll("\r\n", "\r\n ") + "\r\n"); bldr.append(" ").append(t.toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
} }
bldr.append("}"); bldr.append("}");
return bldr.toString(); return bldr.toString();

View File

@ -153,7 +153,7 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject>
} }
KList<String> v = new KList<>(m); KList<String> v = new KList<>(m);
possibleKeys = v.toArray(new String[v.size()]); possibleKeys = v.toArray(new String[0]);
return possibleKeys; return possibleKeys;
} }
@ -201,7 +201,7 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject>
} }
KList<String> v = new KList<>(m); KList<String> v = new KList<>(m);
possibleKeys = v.toArray(new String[v.size()]); possibleKeys = v.toArray(new String[0]);
return possibleKeys; return possibleKeys;
} }

View File

@ -79,7 +79,7 @@ public class ResourceLoader<T extends IrisRegistrant>
} }
KList<String> v = new KList<>(m); KList<String> v = new KList<>(m);
preferredKeys = v.toArray(new String[v.size()]); preferredKeys = v.toArray(new String[0]);
return preferredKeys; return preferredKeys;
} }
@ -116,7 +116,7 @@ public class ResourceLoader<T extends IrisRegistrant>
} }
KList<String> v = new KList<>(m); KList<String> v = new KList<>(m);
possibleKeys = v.toArray(new String[v.size()]); possibleKeys = v.toArray(new String[0]);
return possibleKeys; return possibleKeys;
} }

View File

@ -117,7 +117,7 @@ public class V
try try
{ {
return (local ? Violator.getDeclaredMethod(o.getClass(), method, par.toArray(new Class<?>[par.size()])) : Violator.getMethod(o.getClass(), method, par.toArray(new Class<?>[par.size()]))).invoke(o, parameters); return (local ? Violator.getDeclaredMethod(o.getClass(), method, par.toArray(new Class<?>[0])) : Violator.getMethod(o.getClass(), method, par.toArray(new Class<?>[0]))).invoke(o, parameters);
} }
catch(Throwable e) catch(Throwable e)

View File

@ -31,28 +31,28 @@ public class Violator
{ {
Constructor<?> co = (Constructor<?>) o; Constructor<?> co = (Constructor<?>) o;
String mx = ""; StringBuilder mx = new StringBuilder();
for(Class<?> i : co.getParameterTypes()) for(Class<?> i : co.getParameterTypes())
{ {
mx += "," + i.getCanonicalName(); mx.append(",").append(i.getCanonicalName());
} }
mx = mx.length() >= 1 ? mx.substring(1) : mx; mx = new StringBuilder(mx.length() >= 1 ? mx.substring(1) : mx.toString());
return id(co.getDeclaringClass(), null) + "(" + mx + ")"; return id(co.getDeclaringClass(), null) + "(" + mx + ")";
} }
if(o instanceof Method) if(o instanceof Method)
{ {
String mx = ""; StringBuilder mx = new StringBuilder();
for(Class<?> i : ((Method) o).getParameterTypes()) for(Class<?> i : ((Method) o).getParameterTypes())
{ {
mx += "," + i.getCanonicalName(); mx.append(",").append(i.getCanonicalName());
} }
mx = mx.length() >= 1 ? mx.substring(1) : mx; mx = new StringBuilder(mx.length() >= 1 ? mx.substring(1) : mx.toString());
return id(((Method) o).getDeclaringClass(), null) + "." + ((Method) o).getName() + "(" + mx + ")"; return id(((Method) o).getDeclaringClass(), null) + "." + ((Method) o).getName() + "(" + mx + ")";
} }
@ -83,14 +83,14 @@ public class Violator
public static Constructor<?> getConstructor(Class<?> c, Class<?>... params) throws NoSuchMethodException, SecurityException public static Constructor<?> getConstructor(Class<?> c, Class<?>... params) throws NoSuchMethodException, SecurityException
{ {
String mx = ""; StringBuilder mx = new StringBuilder();
for(Class<?> i : params) for(Class<?> i : params)
{ {
mx += "," + i.getCanonicalName(); mx.append(",").append(i.getCanonicalName());
} }
mx = mx.length() >= 1 ? mx.substring(1) : mx; mx = new StringBuilder(mx.length() >= 1 ? mx.substring(1) : mx.toString());
if(!h(id(c, null) + "(" + mx + ")")) if(!h(id(c, null) + "(" + mx + ")"))
{ {
@ -159,14 +159,14 @@ public class Violator
public static Method getMethod(Class<?> c, String name, Class<?>... pars) throws Throwable public static Method getMethod(Class<?> c, String name, Class<?>... pars) throws Throwable
{ {
String iv = ""; String iv = "";
String mx = ""; StringBuilder mx = new StringBuilder();
for(Class<?> i : pars) for(Class<?> i : pars)
{ {
mx += "," + i.getCanonicalName(); mx.append(",").append(i.getCanonicalName());
} }
mx = mx.length() >= 1 ? mx.substring(1) : mx; mx = new StringBuilder(mx.length() >= 1 ? mx.substring(1) : mx.toString());
iv = id(c, null) + "." + name + "(" + mx + ")"; iv = id(c, null) + "." + name + "(" + mx + ")";
if(!h(iv)) if(!h(iv))
@ -191,7 +191,7 @@ public class Violator
try try
{ {
Constructor<?> co = getConstructor(c, cv.toArray(new Class<?>[cv.size()])); Constructor<?> co = getConstructor(c, cv.toArray(new Class<?>[0]));
return (T) co.newInstance(parameters); return (T) co.newInstance(parameters);
} }
@ -206,14 +206,14 @@ public class Violator
public static Method getDeclaredMethod(Class<?> c, String name, Class<?>... pars) throws Throwable public static Method getDeclaredMethod(Class<?> c, String name, Class<?>... pars) throws Throwable
{ {
String iv = ""; String iv = "";
String mx = ""; StringBuilder mx = new StringBuilder();
for(Class<?> i : pars) for(Class<?> i : pars)
{ {
mx += "," + i.getCanonicalName(); mx.append(",").append(i.getCanonicalName());
} }
mx = mx.length() >= 1 ? mx.substring(1) : mx; mx = new StringBuilder(mx.length() >= 1 ? mx.substring(1) : mx.toString());
iv = id(c, null) + "." + name + "(" + mx + ")"; iv = id(c, null) + "." + name + "(" + mx + ")";
if(!h(iv)) if(!h(iv))

View File

@ -115,7 +115,7 @@ public class VirtualCommand
return true; return true;
} }
return command.handle(vs, chain.toArray(new String[chain.size()])); return command.handle(vs, chain.toArray(new String[0]));
} }
private boolean checkPermissions(CommandSender sender, ICommand command2) private boolean checkPermissions(CommandSender sender, ICommand command2)