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:
yueh
2014-09-30 22:59:49 +02:00
parent d8da97d2af
commit 7fa7e43c29
25 changed files with 86 additions and 80 deletions
@@ -64,21 +64,21 @@ public class Shaped implements ICraftHandler, IWebsiteSerializer
for (int y = 0; y < rows; y++)
{
String row = "";
StringBuilder row = new StringBuilder();
for (int x = 0; x < cols; x++)
{
if ( inputs.get( y ).get( x ).isAir() )
row = row + " ";
row.append( " " );
else
{
row = row + first;
row.append( first );
args.add( first );
args.add( inputs.get( y ).get( x ) );
first++;
}
}
args.add( y, row );
args.add( y, row.toString() );
}
ItemStack outIS = output.getItemStack();
@@ -57,9 +57,10 @@ public class Shapeless implements ICraftHandler, IWebsiteSerializer
throw new RegistrationError( "Error while adding shapeless recipe." );
}
}
@Override
public boolean canCraft(ItemStack reqOutput) throws RegistrationError, MissingIngredientError {
public boolean canCraft(ItemStack reqOutput) throws RegistrationError, MissingIngredientError
{
for (IIngredient i : inputs)
{
@@ -74,26 +75,27 @@ public class Shapeless implements ICraftHandler, IWebsiteSerializer
}
}
}
return Platform.isSameItemPrecise( output.getItemStack(),reqOutput );
return Platform.isSameItemPrecise( output.getItemStack(), reqOutput );
}
@Override
public String getPattern( RecipeHandler h) {
String o = "shapeless "+output.getQty()+"\n";
public String getPattern(RecipeHandler h)
{
StringBuilder o = new StringBuilder( "shapeless " + output.getQty() + "\n" );
o += h.getName(output)+"\n";
for ( int y = 0; y < inputs.size(); y++ )
o.append( h.getName( output ) + "\n" );
for (int y = 0; y < inputs.size(); y++)
{
IIngredient i = inputs.get(y);
IIngredient i = inputs.get( y );
if ( i.isAir() )
o += "air"+( y +1 == inputs.size() ? "\n" : " " );
o.append( "air" + (y + 1 == inputs.size() ? "\n" : " ") );
else
o += h.getName(i)+( y +1 == inputs.size() ? "\n" : " " );
o.append( h.getName( i ) + (y + 1 == inputs.size() ? "\n" : " ") );
}
return o.trim();
return o.toString().trim();
}
}