Some performance or memory optimizations
Replaced String concat in loops with StringBuilder (performance) Replaced for with keySet + Map.get() through for with entrySet (perf) Changed inner classes to static classes, mostly struct like (memory)
This commit is contained in:
@@ -31,10 +31,11 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
|
||||
return !disable;
|
||||
}
|
||||
|
||||
public ShapedRecipe(ItemStack result, Object... recipe) {
|
||||
public ShapedRecipe(ItemStack result, Object... recipe)
|
||||
{
|
||||
output = result.copy();
|
||||
|
||||
String shape = "";
|
||||
StringBuilder shape = new StringBuilder();
|
||||
int idx = 0;
|
||||
|
||||
if ( recipe[idx] instanceof Boolean )
|
||||
@@ -57,7 +58,7 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
|
||||
for (String s : parts)
|
||||
{
|
||||
width = s.length();
|
||||
shape += s;
|
||||
shape.append( s );
|
||||
}
|
||||
|
||||
height = parts.length;
|
||||
@@ -67,7 +68,7 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
|
||||
while (recipe[idx] instanceof String)
|
||||
{
|
||||
String s = (String) recipe[idx++];
|
||||
shape += s;
|
||||
shape.append( s );
|
||||
width = s.length();
|
||||
height++;
|
||||
}
|
||||
@@ -75,13 +76,13 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
|
||||
|
||||
if ( width * height != shape.length() )
|
||||
{
|
||||
String ret = "Invalid shaped ore recipe: ";
|
||||
StringBuilder ret = new StringBuilder( "Invalid shaped ore recipe: " );
|
||||
for (Object tmp : recipe)
|
||||
{
|
||||
ret += tmp + ", ";
|
||||
ret.append( tmp + ", " );
|
||||
}
|
||||
ret += output;
|
||||
throw new RuntimeException( ret );
|
||||
ret.append( output );
|
||||
throw new RuntimeException( ret.toString() );
|
||||
}
|
||||
|
||||
HashMap<Character, Object> itemMap = new HashMap<Character, Object>();
|
||||
@@ -97,19 +98,19 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
|
||||
}
|
||||
else
|
||||
{
|
||||
String ret = "Invalid shaped ore recipe: ";
|
||||
StringBuilder ret = new StringBuilder( "Invalid shaped ore recipe: " );
|
||||
for (Object tmp : recipe)
|
||||
{
|
||||
ret += tmp + ", ";
|
||||
ret.append( tmp + ", " );
|
||||
}
|
||||
ret += output;
|
||||
throw new RuntimeException( ret );
|
||||
ret.append( output );
|
||||
throw new RuntimeException( ret.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
input = new Object[width * height];
|
||||
int x = 0;
|
||||
for (char chr : shape.toCharArray())
|
||||
for (char chr : shape.toString().toCharArray())
|
||||
{
|
||||
input[x++] = itemMap.get( chr );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user