Performance pass 5 (String concatenation in loop)

This commit is contained in:
Andrew 2020-10-15 22:46:05 -07:00
parent 1b88d3d785
commit d9d0f426e4
5 changed files with 45 additions and 45 deletions

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

@ -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,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);
@ -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

@ -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))
@ -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))