diff --git a/src/com/lushprojects/circuitjs1/client/CompositeElm.java b/src/com/lushprojects/circuitjs1/client/CompositeElm.java index 9bc1bc72..1009462b 100644 --- a/src/com/lushprojects/circuitjs1/client/CompositeElm.java +++ b/src/com/lushprojects/circuitjs1/client/CompositeElm.java @@ -207,7 +207,7 @@ public String dumpElements(int mask) { } // are n1 and n2 connected internally somehow? - public boolean getConnection(int n1, int n2) { + public boolean getConnectionSlow(int n1, int n2) { Vector connectedNodes = new Vector(); // keep list of nodes connected to n1 @@ -242,8 +242,35 @@ public boolean getConnection(int n1, int n2) { return false; } + HashMap connectionMap; + HashMap groundConnectionMap; + + public boolean getConnection(int n1, int n2) { + if (connectionMap == null) + connectionMap = new HashMap(); + IntPair key = new IntPair(n1, n2); + Boolean result = connectionMap.get(key); + if (result != null) + return result; + result = getConnectionSlow(n1, n2); + connectionMap.put(key, result); + return result; + } + // is n1 connected to ground somehow? public boolean hasGroundConnection(int n1) { + if (groundConnectionMap == null) + groundConnectionMap = new HashMap(); + Integer key = n1; + Boolean result = groundConnectionMap.get(key); + if (result != null) + return result; + result = hasGroundConnectionSlow(n1); + groundConnectionMap.put(key, result); + return result; + } + + public boolean hasGroundConnectionSlow(int n1) { Vector connectedNodes = new Vector(); // keep list of nodes connected to n1