From 4cebc973ca96e6a60780deeba9ca78a5a4be56fe Mon Sep 17 00:00:00 2001 From: hneemann Date: Fri, 25 Dec 2020 16:31:50 +0100 Subject: [PATCH] improves performance of model creation --- .../de/neemann/digital/draw/model/Net.java | 9 ++++--- .../neemann/digital/draw/model/NetList.java | 25 +++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/neemann/digital/draw/model/Net.java b/src/main/java/de/neemann/digital/draw/model/Net.java index 3d923e161..6519a0c91 100644 --- a/src/main/java/de/neemann/digital/draw/model/Net.java +++ b/src/main/java/de/neemann/digital/draw/model/Net.java @@ -137,7 +137,8 @@ public class Net { } /** - * Add all given pins to the net + * Add all given pins to the net. + * Used during custom component connection. * * @param p the pins */ @@ -146,7 +147,8 @@ public class Net { } /** - * Add all given pins to the net + * Add all given pins to the net. + * Used during custom component connection. * * @param otherNet the other net */ @@ -238,7 +240,8 @@ public class Net { } /** - * Removes a pin from the net + * Removes a pin from the net. + * Used during custom component connection. * * @param p the pin to remove * @throws PinException is thrown if pin is not present diff --git a/src/main/java/de/neemann/digital/draw/model/NetList.java b/src/main/java/de/neemann/digital/draw/model/NetList.java index 0a9d64435..3ca12f695 100644 --- a/src/main/java/de/neemann/digital/draw/model/NetList.java +++ b/src/main/java/de/neemann/digital/draw/model/NetList.java @@ -21,6 +21,7 @@ import java.util.Iterator; public class NetList implements Iterable { private final ArrayList netList; + private HashMap posMap; /** * Creates a net list from the given circuit @@ -130,7 +131,8 @@ public class NetList implements Iterable { } /** - * Adds a complete net list to this net list + * Adds a complete net list to this net list. + * Used during custom component connection. * * @param netList the net list to add */ @@ -139,17 +141,18 @@ public class NetList implements Iterable { } /** - * Adds a pin to this net list - * Used only during model creation + * Adds a pin to this net list. + * Used only during model creation. * * @param pin the pin to add */ public void add(Pin pin) { - for (Net net : netList) - if (net.contains(pin.getPos())) { - net.add(pin); - return; - } + if (posMap == null) + posMap = getAllNetPositions(); + + Net net = posMap.get(pin.getPos()); + if (net != null) + net.add(pin); } private void add(Wire w) { @@ -188,7 +191,8 @@ public class NetList implements Iterable { } /** - * Returns the net of the given pin + * Returns the net of the given pin. + * Used during custom component connection. * * @param p the pin * @return the net or null if not found @@ -222,7 +226,8 @@ public class NetList implements Iterable { } /** - * Removes a net from this net list + * Removes a net from this net list. + * Used during custom component connection. * * @param childNet the net to remove */