Merge pull request #207 from yueh/performance-optimizations

Some performance or memory optimizations
This commit is contained in:
Chris
2014-09-30 15:07:13 -07:00
25 changed files with 86 additions and 80 deletions
@@ -33,7 +33,7 @@ import appeng.core.localization.ButtonToolTips;
public class GuiImgButton extends GuiButton implements ITooltip public class GuiImgButton extends GuiButton implements ITooltip
{ {
class EnumPair static class EnumPair
{ {
final Enum setting; final Enum setting;
@@ -63,7 +63,7 @@ public class GuiImgButton extends GuiButton implements ITooltip
} }
class BtnAppearance static class BtnAppearance
{ {
public int index; public int index;
@@ -23,7 +23,7 @@ public class RenderBlocksWorkaround extends RenderBlocks
public EnumSet<ForgeDirection> renderFaces = EnumSet.allOf( ForgeDirection.class ); public EnumSet<ForgeDirection> renderFaces = EnumSet.allOf( ForgeDirection.class );
public EnumSet<ForgeDirection> faces = EnumSet.allOf( ForgeDirection.class ); public EnumSet<ForgeDirection> faces = EnumSet.allOf( ForgeDirection.class );
private class LightingCache implements ISimplifiedBundle private static class LightingCache implements ISimplifiedBundle
{ {
public IIcon rXPos; public IIcon rXPos;
@@ -42,7 +42,7 @@ public class ContainerInterfaceTerminal extends AEBaseContainer
static private long autoBase = Long.MIN_VALUE; static private long autoBase = Long.MIN_VALUE;
class InvTracker static class InvTracker
{ {
final long which = autoBase++; final long which = autoBase++;
@@ -76,7 +76,7 @@ public class ContainerInterfaceTerminal extends AEBaseContainer
NBTTagCompound data = new NBTTagCompound(); NBTTagCompound data = new NBTTagCompound();
class PatternInvSlot extends WrapperInvSlot static class PatternInvSlot extends WrapperInvSlot
{ {
public PatternInvSlot(IInventory inv) { public PatternInvSlot(IInventory inv) {
+1 -1
View File
@@ -196,7 +196,7 @@ public class ApiPart implements IPartHelper
} }
} }
class DefaultPackageClassNameRemapper extends Remapper static class DefaultPackageClassNameRemapper extends Remapper
{ {
public final HashMap<String, String> inputOutput = new HashMap<String, String>(); public final HashMap<String, String> inputOutput = new HashMap<String, String>();
@@ -9,7 +9,7 @@ import appeng.api.features.IWorldGen;
public class WorldGenRegistry implements IWorldGen public class WorldGenRegistry implements IWorldGen
{ {
private class TypeSet private static class TypeSet
{ {
final HashSet<Class<? extends WorldProvider>> badProviders = new HashSet<Class<? extends WorldProvider>>(); final HashSet<Class<? extends WorldProvider>> badProviders = new HashSet<Class<? extends WorldProvider>>();
@@ -124,14 +124,14 @@ public class CraftingJob implements Runnable, ICraftingJob
missing.add( what ); missing.add( what );
} }
class twoIntegers static class TwoIntegers
{ {
public final long perOp = 0; public final long perOp = 0;
public final long times = 0; public final long times = 0;
} }
final HashMap<String, twoIntegers> opsAndMultiplier = new HashMap<String, twoIntegers>(); final HashMap<String, TwoIntegers> opsAndMultiplier = new HashMap<String, TwoIntegers>();
@Override @Override
public void run() public void run()
@@ -154,7 +154,7 @@ public class CraftingJob implements Runnable, ICraftingJob
for (String s : opsAndMultiplier.keySet()) for (String s : opsAndMultiplier.keySet())
{ {
twoIntegers ti = opsAndMultiplier.get( s ); TwoIntegers ti = opsAndMultiplier.get( s );
AELog.crafting( s + " * " + ti.times + " = " + (ti.perOp * ti.times) ); AELog.crafting( s + " * " + ti.times + " = " + (ti.perOp * ti.times) );
} }
@@ -180,7 +180,7 @@ public class CraftingJob implements Runnable, ICraftingJob
for (String s : opsAndMultiplier.keySet()) for (String s : opsAndMultiplier.keySet())
{ {
twoIntegers ti = opsAndMultiplier.get( s ); TwoIntegers ti = opsAndMultiplier.get( s );
AELog.crafting( s + " * " + ti.times + " = " + (ti.perOp * ti.times) ); AELog.crafting( s + " * " + ti.times + " = " + (ti.perOp * ti.times) );
} }
@@ -41,7 +41,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
final boolean isCrafting; final boolean isCrafting;
public int priority = 0; public int priority = 0;
class TestLookup static class TestLookup
{ {
final int slot; final int slot;
@@ -13,7 +13,7 @@ public class CompassManager
public static final CompassManager instance = new CompassManager(); public static final CompassManager instance = new CompassManager();
class CompassRequest static class CompassRequest
{ {
final int hash; final int hash;
@@ -19,7 +19,7 @@ import cpw.mods.fml.common.IWorldGenerator;
final public class MeteoriteWorldGen implements IWorldGenerator final public class MeteoriteWorldGen implements IWorldGenerator
{ {
class myGen implements ICompassCallback static class MyGen implements ICompassCallback
{ {
double distance = 0; double distance = 0;
+1 -1
View File
@@ -40,7 +40,7 @@ import cpw.mods.fml.common.gameevent.TickEvent.WorldTickEvent;
public class TickHandler public class TickHandler
{ {
class HandlerRep static class HandlerRep
{ {
public Queue<AEBaseTile> tiles = new LinkedList<AEBaseTile>(); public Queue<AEBaseTile> tiles = new LinkedList<AEBaseTile>();
@@ -60,7 +60,7 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
instance = this; instance = this;
} }
class SlightlyBetterSort implements Comparator<String> static class SlightlyBetterSort implements Comparator<String>
{ {
final Pattern p; final Pattern p;
@@ -33,7 +33,7 @@ import cpw.mods.fml.relauncher.SideOnly;
public class ItemMultiPart extends AEBaseItem implements IPartItem, IItemGroup public class ItemMultiPart extends AEBaseItem implements IPartItem, IItemGroup
{ {
class PartTypeIst static class PartTypeIst
{ {
PartType part; PartType part;
+4 -3
View File
@@ -3,6 +3,7 @@ package appeng.me;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import appeng.api.AEApi; import appeng.api.AEApi;
@@ -34,10 +35,10 @@ public class Grid implements IGrid
this.pivot = center; this.pivot = center;
HashMap<Class<? extends IGridCache>, IGridCache> myCaches = AEApi.instance().registries().gridCache().createCacheInstance( this ); HashMap<Class<? extends IGridCache>, IGridCache> myCaches = AEApi.instance().registries().gridCache().createCacheInstance( this );
for (Class<? extends IGridCache> c : myCaches.keySet()) for (Entry<Class<? extends IGridCache>, IGridCache> c : myCaches.entrySet())
{ {
bus.readClass( c, myCaches.get( c ).getClass() ); bus.readClass( c.getKey(), c.getValue().getClass() );
caches.put( c, new GridCacheWrapper( myCaches.get( c ) ) ); caches.put( c.getKey(), new GridCacheWrapper( c.getValue() ) );
} }
postEvent( new MENetworkPostCacheConstruction() ); postEvent( new MENetworkPostCacheConstruction() );
+6 -5
View File
@@ -4,6 +4,7 @@ import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import appeng.api.networking.IGridNode; import appeng.api.networking.IGridNode;
@@ -14,7 +15,7 @@ import appeng.core.AELog;
public class NetworkEventBus public class NetworkEventBus
{ {
class NetworkEventDone extends Throwable static class NetworkEventDone extends Throwable
{ {
private static final long serialVersionUID = -3079021487019171205L; private static final long serialVersionUID = -3079021487019171205L;
@@ -129,17 +130,17 @@ public class NetworkEventBus
{ {
if ( subscribers != null ) if ( subscribers != null )
{ {
for (Class o : subscribers.keySet()) for (Entry<Class, MENetworkEventInfo> subscriber : subscribers.entrySet())
{ {
MENetworkEventInfo target = subscribers.get( o ); MENetworkEventInfo target = subscriber.getValue();
GridCacheWrapper cache = g.caches.get( o ); GridCacheWrapper cache = g.caches.get( subscriber.getKey() );
if ( cache != null ) if ( cache != null )
{ {
x++; x++;
target.invoke( cache.myCache, e ); target.invoke( cache.myCache, e );
} }
for (IGridNode obj : g.getMachines( o )) for (IGridNode obj : g.getMachines( subscriber.getKey() ))
{ {
x++; x++;
target.invoke( obj.getMachine(), e ); target.invoke( obj.getMachine(), e );
+1 -1
View File
@@ -86,7 +86,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
final private SetMultimap<IAEStack, CraftingWatcher> interests = HashMultimap.create(); final private SetMultimap<IAEStack, CraftingWatcher> interests = HashMultimap.create();
final public GenericInterestManager<CraftingWatcher> interestManager = new GenericInterestManager<CraftingWatcher>( interests ); final public GenericInterestManager<CraftingWatcher> interestManager = new GenericInterestManager<CraftingWatcher>( interests );
class ActiveCpuIterator implements Iterator<ICraftingCPU> static class ActiveCpuIterator implements Iterator<ICraftingCPU>
{ {
final Iterator<CraftingCPUCluster> i; final Iterator<CraftingCPUCluster> i;
@@ -58,7 +58,7 @@ import cpw.mods.fml.common.FMLCommonHandler;
public class CraftingCPUCluster implements IAECluster, ICraftingCPU public class CraftingCPUCluster implements IAECluster, ICraftingCPU
{ {
class TaskProgress static class TaskProgress
{ {
long value; long value;
@@ -27,7 +27,7 @@ import appeng.util.inv.ItemSlot;
public class MEMonitorIInventory implements IMEInventory<IAEItemStack>, IMEMonitor<IAEItemStack> public class MEMonitorIInventory implements IMEInventory<IAEItemStack>, IMEMonitor<IAEItemStack>
{ {
class CachedItemStack static class CachedItemStack
{ {
public CachedItemStack(ItemStack is) public CachedItemStack(ItemStack is)
@@ -31,10 +31,11 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
return !disable; return !disable;
} }
public ShapedRecipe(ItemStack result, Object... recipe) { public ShapedRecipe(ItemStack result, Object... recipe)
{
output = result.copy(); output = result.copy();
String shape = ""; StringBuilder shape = new StringBuilder();
int idx = 0; int idx = 0;
if ( recipe[idx] instanceof Boolean ) if ( recipe[idx] instanceof Boolean )
@@ -57,7 +58,7 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
for (String s : parts) for (String s : parts)
{ {
width = s.length(); width = s.length();
shape += s; shape.append( s );
} }
height = parts.length; height = parts.length;
@@ -67,7 +68,7 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
while (recipe[idx] instanceof String) while (recipe[idx] instanceof String)
{ {
String s = (String) recipe[idx++]; String s = (String) recipe[idx++];
shape += s; shape.append( s );
width = s.length(); width = s.length();
height++; height++;
} }
@@ -75,13 +76,13 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
if ( width * height != shape.length() ) if ( width * height != shape.length() )
{ {
String ret = "Invalid shaped ore recipe: "; StringBuilder ret = new StringBuilder( "Invalid shaped ore recipe: " );
for (Object tmp : recipe) for (Object tmp : recipe)
{ {
ret += tmp + ", "; ret.append( tmp + ", " );
} }
ret += output; ret.append( output );
throw new RuntimeException( ret ); throw new RuntimeException( ret.toString() );
} }
HashMap<Character, Object> itemMap = new HashMap<Character, Object>(); HashMap<Character, Object> itemMap = new HashMap<Character, Object>();
@@ -97,19 +98,19 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
} }
else else
{ {
String ret = "Invalid shaped ore recipe: "; StringBuilder ret = new StringBuilder( "Invalid shaped ore recipe: " );
for (Object tmp : recipe) for (Object tmp : recipe)
{ {
ret += tmp + ", "; ret.append( tmp + ", " );
} }
ret += output; ret.append( output );
throw new RuntimeException( ret ); throw new RuntimeException( ret.toString() );
} }
} }
input = new Object[width * height]; input = new Object[width * height];
int x = 0; int x = 0;
for (char chr : shape.toCharArray()) for (char chr : shape.toString().toCharArray())
{ {
input[x++] = itemMap.get( chr ); input[x++] = itemMap.get( chr );
} }
@@ -24,7 +24,8 @@ public class ShapelessRecipe implements IRecipe, IRecipeBakeable
return !disable; return !disable;
} }
public ShapelessRecipe(ItemStack result, Object... recipe) { public ShapelessRecipe(ItemStack result, Object... recipe)
{
output = result.copy(); output = result.copy();
for (Object in : recipe) for (Object in : recipe)
{ {
@@ -34,13 +35,13 @@ public class ShapelessRecipe implements IRecipe, IRecipeBakeable
} }
else else
{ {
String ret = "Invalid shapeless ore recipe: "; StringBuilder ret = new StringBuilder( "Invalid shapeless ore recipe: " );
for (Object tmp : recipe) for (Object tmp : recipe)
{ {
ret += tmp + ", "; ret.append( tmp + ", " );
} }
ret += output; ret.append( output );
throw new RuntimeException( ret ); throw new RuntimeException( ret.toString() );
} }
} }
} }
@@ -64,21 +64,21 @@ public class Shaped implements ICraftHandler, IWebsiteSerializer
for (int y = 0; y < rows; y++) for (int y = 0; y < rows; y++)
{ {
String row = ""; StringBuilder row = new StringBuilder();
for (int x = 0; x < cols; x++) for (int x = 0; x < cols; x++)
{ {
if ( inputs.get( y ).get( x ).isAir() ) if ( inputs.get( y ).get( x ).isAir() )
row = row + " "; row.append( " " );
else else
{ {
row = row + first; row.append( first );
args.add( first ); args.add( first );
args.add( inputs.get( y ).get( x ) ); args.add( inputs.get( y ).get( x ) );
first++; first++;
} }
} }
args.add( y, row ); args.add( y, row.toString() );
} }
ItemStack outIS = output.getItemStack(); ItemStack outIS = output.getItemStack();
@@ -59,7 +59,8 @@ public class Shapeless implements ICraftHandler, IWebsiteSerializer
} }
@Override @Override
public boolean canCraft(ItemStack reqOutput) throws RegistrationError, MissingIngredientError { public boolean canCraft(ItemStack reqOutput) throws RegistrationError, MissingIngredientError
{
for (IIngredient i : inputs) for (IIngredient i : inputs)
{ {
@@ -75,25 +76,26 @@ public class Shapeless implements ICraftHandler, IWebsiteSerializer
} }
} }
return Platform.isSameItemPrecise( output.getItemStack(),reqOutput ); return Platform.isSameItemPrecise( output.getItemStack(), reqOutput );
} }
@Override @Override
public String getPattern( RecipeHandler h) { public String getPattern(RecipeHandler h)
String o = "shapeless "+output.getQty()+"\n"; {
StringBuilder o = new StringBuilder( "shapeless " + output.getQty() + "\n" );
o += h.getName(output)+"\n"; o.append( h.getName( output ) + "\n" );
for ( int y = 0; y < inputs.size(); y++ ) for (int y = 0; y < inputs.size(); y++)
{ {
IIngredient i = inputs.get(y); IIngredient i = inputs.get( y );
if ( i.isAir() ) if ( i.isAir() )
o += "air"+( y +1 == inputs.size() ? "\n" : " " ); o.append( "air" + (y + 1 == inputs.size() ? "\n" : " ") );
else 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();
} }
} }
@@ -60,17 +60,17 @@ public class VersionChecker implements Runnable
yc.setRequestProperty( "User-Agent", "AE2/" + AEConfig.VERSION + " (Channel:" + AEConfig.CHANNEL + "," + MCVersion.replace( " ", ":" ) + ")" ); yc.setRequestProperty( "User-Agent", "AE2/" + AEConfig.VERSION + " (Channel:" + AEConfig.CHANNEL + "," + MCVersion.replace( " ", ":" ) + ")" );
BufferedReader in = new BufferedReader( new InputStreamReader( yc.getInputStream() ) ); BufferedReader in = new BufferedReader( new InputStreamReader( yc.getInputStream() ) );
String Version = ""; StringBuilder Version = new StringBuilder();
String inputLine; String inputLine;
while ((inputLine = in.readLine()) != null) while ((inputLine = in.readLine()) != null)
Version += inputLine; Version.append( inputLine );
in.close(); in.close();
if ( Version.length() > 2 ) if ( Version.length() > 2 )
{ {
JsonElement element = (new JsonParser()).parse( Version ); JsonElement element = (new JsonParser()).parse( Version.toString() );
int version = element.getAsJsonObject().get( "FormatVersion" ).getAsInt(); int version = element.getAsJsonObject().get( "FormatVersion" ).getAsInt();
if ( version == 1 ) if ( version == 1 )
@@ -31,12 +31,12 @@ public class StorageHelper
return instance; return instance;
} }
class triggerUpdates implements ISpatialVisitor static class TriggerUpdates implements ISpatialVisitor
{ {
final World dst; final World dst;
public triggerUpdates(World dst2) { public TriggerUpdates(World dst2) {
dst = dst2; dst = dst2;
} }
@@ -48,7 +48,7 @@ public class StorageHelper
} }
} }
class WrapInMatrixFrame implements ISpatialVisitor static class WrapInMatrixFrame implements ISpatialVisitor
{ {
final World dst; final World dst;
@@ -68,7 +68,7 @@ public class StorageHelper
} }
} }
class TelDestination static class TelDestination
{ {
TelDestination(World _dim, AxisAlignedBB srcBox, double _x, double _y, double _z, int tileX, int tileY, int tileZ) { TelDestination(World _dim, AxisAlignedBB srcBox, double _x, double _y, double _z, int tileX, int tileY, int tileZ) {
@@ -91,7 +91,7 @@ public class StorageHelper
final int zOff; final int zOff;
} }
class METeleporter extends Teleporter static class METeleporter extends Teleporter
{ {
final TelDestination dest; final TelDestination dest;
@@ -303,11 +303,11 @@ public class StorageHelper
for (WorldCoord wc : cSrc.updates) for (WorldCoord wc : cSrc.updates)
cSrc.world.notifyBlockOfNeighborChange( wc.x, wc.y, wc.z, Platform.air ); cSrc.world.notifyBlockOfNeighborChange( wc.x, wc.y, wc.z, Platform.air );
transverseEdges( x - 1, y - 1, z - 1, x + scaleX + 1, y + scaleY + 1, z + scaleZ + 1, new triggerUpdates( src ) ); transverseEdges( x - 1, y - 1, z - 1, x + scaleX + 1, y + scaleY + 1, z + scaleZ + 1, new TriggerUpdates( src ) );
transverseEdges( i - 1, j - 1, k - 1, i + scaleX + 1, j + scaleY + 1, k + scaleZ + 1, new triggerUpdates( dst ) ); transverseEdges( i - 1, j - 1, k - 1, i + scaleX + 1, j + scaleY + 1, k + scaleZ + 1, new TriggerUpdates( dst ) );
transverseEdges( x, y, z, x + scaleX, y + scaleY, z + scaleZ, new triggerUpdates( src ) ); transverseEdges( x, y, z, x + scaleX, y + scaleY, z + scaleZ, new TriggerUpdates( src ) );
transverseEdges( i, j, k, i + scaleX, j + scaleY, k + scaleZ, new triggerUpdates( dst ) ); transverseEdges( i, j, k, i + scaleX, j + scaleY, k + scaleZ, new TriggerUpdates( dst ) );
/* /*
* IChunkProvider cp = dest.getChunkProvider(); if ( cp instanceof ChunkProviderServer ) { ChunkProviderServer * IChunkProvider cp = dest.getChunkProvider(); if ( cp instanceof ChunkProviderServer ) { ChunkProviderServer
@@ -13,7 +13,7 @@ import net.minecraft.item.ItemStack;
public class WrapperChainedInventory implements IInventory public class WrapperChainedInventory implements IInventory
{ {
class InvOffset static class InvOffset
{ {
int offset; int offset;
@@ -13,7 +13,7 @@ public class OreHelper
public static final OreHelper instance = new OreHelper(); public static final OreHelper instance = new OreHelper();
class ItemRef static class ItemRef
{ {
ItemRef(ItemStack stack) ItemRef(ItemStack stack)
@@ -51,7 +51,7 @@ public class OreHelper
} }
class OreResult static class OreResult
{ {
public OreReference oreValue = null; public OreReference oreValue = null;