Replaced LinkedList with ArrayList or ArrayDeque when applicable. (#3392)

This commit is contained in:
yueh
2018-05-27 21:15:50 +02:00
committed by GitHub
parent 62435a65f1
commit d7b97fa7b8
37 changed files with 118 additions and 117 deletions
+7 -6
View File
@@ -19,11 +19,12 @@
package appeng.me;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
@@ -64,7 +65,7 @@ public class GridNode implements IGridNode, IPathItem
private static final MENetworkChannelsChanged EVENT = new MENetworkChannelsChanged();
private static final int[] CHANNEL_COUNT = { 0, 8, 32 };
private final List<IGridConnection> connections = new LinkedList<>();
private final List<IGridConnection> connections = new ArrayList<>();
private final IGridBlock gridProxy;
// old power draw, used to diff
private double previousDraw = 0.0;
@@ -163,14 +164,14 @@ public class GridNode implements IGridNode, IPathItem
{
final Object tracker = new Object();
LinkedList<GridNode> nextRun = new LinkedList<>();
Deque<GridNode> nextRun = new ArrayDeque<>();
nextRun.add( this );
this.visitorIterationNumber = tracker;
if( g instanceof IGridConnectionVisitor )
{
final LinkedList<IGridConnection> nextConn = new LinkedList<>();
final Deque<IGridConnection> nextConn = new ArrayDeque<>();
final IGridConnectionVisitor gcv = (IGridConnectionVisitor) g;
while( !nextRun.isEmpty() )
@@ -181,7 +182,7 @@ public class GridNode implements IGridNode, IPathItem
}
final Iterable<GridNode> thisRun = nextRun;
nextRun = new LinkedList<>();
nextRun = new ArrayDeque<>();
for( final GridNode n : thisRun )
{
@@ -194,7 +195,7 @@ public class GridNode implements IGridNode, IPathItem
while( !nextRun.isEmpty() )
{
final Iterable<GridNode> thisRun = nextRun;
nextRun = new LinkedList<>();
nextRun = new ArrayDeque<>();
for( final GridNode n : thisRun )
{
+3 -3
View File
@@ -19,10 +19,10 @@
package appeng.me.cache;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -215,7 +215,7 @@ public class GridStorageCache implements IStorageGrid
{
this.storageNetworks.clear();
final List<ICellProvider> ll = new LinkedList<ICellProvider>();
final List<ICellProvider> ll = new ArrayList<ICellProvider>();
ll.addAll( this.inactiveCellProviders );
ll.addAll( this.activeCellProviders );
@@ -331,7 +331,7 @@ public class GridStorageCache implements IStorageGrid
private class CellChangeTracker<T extends IAEStack<T>>
{
final List<CellChangeTrackerRecord<T>> data = new LinkedList<>();
final List<CellChangeTrackerRecord<T>> data = new ArrayList<>();
public void postChanges( final IStorageChannel<T> channel, final int i, final IMEInventoryHandler<T> h, final IActionSource actionSrc )
{
+3 -3
View File
@@ -19,10 +19,10 @@
package appeng.me.cache;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@@ -63,7 +63,7 @@ import appeng.tile.networking.TileController;
public class PathGridCache implements IPathingGrid
{
private final LinkedList<PathSegment> active = new LinkedList<>();
private final List<PathSegment> active = new ArrayList<>();
private final Set<TileController> controllers = new HashSet<>();
private final Set<IGridNode> requireChannels = new HashSet<>();
private final Set<IGridNode> blockDense = new HashSet<>();
@@ -154,7 +154,7 @@ public class PathGridCache implements IPathingGrid
final GridConnection gc = (GridConnection) gcc;
if( !( gc.getOtherSide( node ).getMachine() instanceof TileController ) )
{
final List<IPathItem> open = new LinkedList<>();
final List<IPathItem> open = new ArrayList<>();
closedList.add( gc );
open.add( gc );
gc.setControllerRoute( (GridNode) node, true );
+3 -3
View File
@@ -19,8 +19,8 @@
package appeng.me.cache;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import appeng.api.networking.IGrid;
@@ -47,7 +47,7 @@ public class SpatialPylonCache implements ISpatialCache
private DimensionalCoord captureMin;
private DimensionalCoord captureMax;
private boolean isValid = false;
private List<TileSpatialIOPort> ioPorts = new LinkedList<>();
private List<TileSpatialIOPort> ioPorts = new ArrayList<>();
private HashMap<SpatialPylonCluster, SpatialPylonCluster> clusters = new HashMap<>();
public SpatialPylonCache( final IGrid g )
@@ -65,7 +65,7 @@ public class SpatialPylonCache implements ISpatialCache
{
this.clusters = new HashMap<>();
this.ioPorts = new LinkedList<>();
this.ioPorts = new ArrayList<>();
for( final IGridNode gm : grid.getMachines( TileSpatialIOPort.class ) )
{
@@ -23,7 +23,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -90,9 +90,9 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
private final int[] usedOps = new int[3];
private final Map<ICraftingPatternDetails, TaskProgress> tasks = new HashMap<>();
// INSTANCE sate
private final LinkedList<TileCraftingTile> tiles = new LinkedList<>();
private final LinkedList<TileCraftingTile> storage = new LinkedList<>();
private final LinkedList<TileCraftingMonitorTile> status = new LinkedList<>();
private final List<TileCraftingTile> tiles = new ArrayList<>();
private final List<TileCraftingTile> storage = new ArrayList<>();
private final List<TileCraftingMonitorTile> status = new ArrayList<>();
private final HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new HashMap<>();
private ICraftingLink myLastLink;
private String myName = "";
@@ -207,7 +207,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
te.setCoreBlock( false );
te.markDirty();
this.tiles.push( te );
this.tiles.add( 0, te );
if( te.isStorage() )
{
@@ -19,8 +19,9 @@
package appeng.me.helpers;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import com.google.common.collect.Multimap;
@@ -31,7 +32,7 @@ public class GenericInterestManager<T>
{
private final Multimap<IAEStack, T> container;
private LinkedList<SavedTransactions> transactions = null;
private List<SavedTransactions> transactions = null;
private int transDepth = 0;
public GenericInterestManager( final Multimap<IAEStack, T> interests )
@@ -43,7 +44,7 @@ public class GenericInterestManager<T>
{
if( this.transDepth == 0 )
{
this.transactions = new LinkedList<>();
this.transactions = new ArrayList<>();
}
this.transDepth++;
@@ -55,7 +56,7 @@ public class GenericInterestManager<T>
if( this.transDepth == 0 )
{
final LinkedList<SavedTransactions> myActions = this.transactions;
final List<SavedTransactions> myActions = this.transactions;
this.transactions = null;
for( final SavedTransactions t : myActions )
@@ -19,9 +19,9 @@
package appeng.me.pathfinding;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@@ -52,7 +52,7 @@ public class PathSegment
public boolean step()
{
final List<IPathItem> oldOpen = this.open;
this.open = new LinkedList<>();
this.open = new ArrayList<>();
for( final IPathItem i : oldOpen )
{
@@ -19,10 +19,11 @@
package appeng.me.storage;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.NavigableMap;
import java.util.TreeMap;
@@ -45,8 +46,8 @@ import appeng.util.ItemSorters;
public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHandler<T>
{
private static final ThreadLocal<LinkedList> DEPTH_MOD = new ThreadLocal<>();
private static final ThreadLocal<LinkedList> DEPTH_SIM = new ThreadLocal<>();
private static final ThreadLocal<Deque> DEPTH_MOD = new ThreadLocal<>();
private static final ThreadLocal<Deque> DEPTH_SIM = new ThreadLocal<>();
private static final Comparator<Integer> PRIORITY_SORTER = ( o1, o2 ) -> ItemSorters.compareInt( o2, o1 );
private static int currentPass = 0;
@@ -125,7 +126,7 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
private boolean diveList( final NetworkInventoryHandler<T> networkInventoryHandler, final Actionable type )
{
final LinkedList cDepth = this.getDepth( type );
final Deque cDepth = this.getDepth( type );
if( cDepth.contains( networkInventoryHandler ) )
{
return true;
@@ -180,15 +181,15 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
}
}
private LinkedList getDepth( final Actionable type )
private Deque getDepth( final Actionable type )
{
final ThreadLocal<LinkedList> depth = type == Actionable.MODULATE ? DEPTH_MOD : DEPTH_SIM;
final ThreadLocal<Deque> depth = type == Actionable.MODULATE ? DEPTH_MOD : DEPTH_SIM;
LinkedList s = depth.get();
Deque s = depth.get();
if( s == null )
{
depth.set( s = new LinkedList() );
depth.set( s = new ArrayDeque<>() );
}
return s;
@@ -263,7 +264,7 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
private boolean diveIteration( final NetworkInventoryHandler<T> networkInventoryHandler, final Actionable type )
{
final LinkedList cDepth = this.getDepth( type );
final Deque cDepth = this.getDepth( type );
if( cDepth.isEmpty() )
{
currentPass++;