I'll have you arrayned for this

I replaced all the linkedlists of path commands with arraylists because it was actually making the projection exteremely slow.  I could alternatively have reritten all of my for-loops over paths to be for-each instead of index-based, which would have solved the same problem, but I think arraylists are just better in general for this.  it's not like I'm short on memory here.  there's only one instance of me calling .remove(), and it's right after some funky indexing stuff, so a linkedlist wouldn't really help there anyway.
This commit is contained in:
Justin Kunimune 2023-12-07 20:52:55 -05:00
parent ef3628fb67
commit f7d49c1149
4 changed files with 10 additions and 12 deletions

View File

@ -49,6 +49,7 @@ import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.function.BiConsumer;
@ -334,7 +335,7 @@ public class MapDesignerVector extends MapApplication {
else if (elementS instanceof GeographicPath) {
GeographicPath pathS = (GeographicPath) elementS;
List<Path.Command> commandsS = pathS.commands;
List<Path.Command> commandsP = new LinkedList<>();
List<Path.Command> commandsP = new ArrayList<>();
if (commandsS.size() > 2*max(1, step)) {
int j = 0;
while (j < commandsS.size()) {

View File

@ -3,7 +3,6 @@ package image;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import static java.lang.Double.isFinite;
@ -69,7 +68,7 @@ public class Path {
* shift a path by some amount in some direction
*/
public static List<Command> translated(double xShift, double yShift, List<Command> path) {
List<Command> newPath = new LinkedList<>();
List<Command> newPath = new ArrayList<>();
for (Command old: path) {
double[] newArgs = Arrays.copyOf(old.args, old.args.length);
switch (old.type) {
@ -109,7 +108,7 @@ public class Path {
* either or both may be negative.
*/
public static List<Command> scaled(double xScale, double yScale, List<Command> path) {
List<Command> newPath = new LinkedList<>();
List<Command> newPath = new ArrayList<>();
for (Command old: path) {
double[] newArgs = Arrays.copyOf(old.args, old.args.length);
switch (old.type) {
@ -154,7 +153,7 @@ public class Path {
* positive is widdershins and negative is clockwise.
*/
public static List<Command> rotated(double rotation, List<Command> path) {
List<Command> newPath = new LinkedList<>();
List<Command> newPath = new ArrayList<>();
for (Command old: path) {
char newType = old.type;
double[] newArgs = Arrays.copyOf(old.args, old.args.length);

View File

@ -42,7 +42,6 @@ import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
@ -50,7 +49,6 @@ import static java.lang.Double.NaN;
import static java.lang.Double.parseDouble;
import static java.lang.Math.PI;
import static java.lang.Math.hypot;
import static java.lang.Math.min;
import static java.lang.String.format;
import static utils.Math2.linInterp;
import static utils.Math2.max;
@ -78,7 +76,7 @@ public class SVGMap implements Iterable<SVGMap.SVGElement>, SavableImage {
* @throws ParserConfigurationException if the SAXParser object can't be constructed for some reason
*/
public SVGMap(File file) throws IOException, SAXException, ParserConfigurationException {
elements = new LinkedList<>(); // the list elements
elements = new ArrayList<>(); // the list elements
final SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
@ -467,7 +465,7 @@ public class SVGMap implements Iterable<SVGMap.SVGElement>, SavableImage {
*/
public static GeographicPath breakWraps(GeographicPath continuous, double inSize, boolean strict) { //break excessively long commands, as they are likely wrapping over a discontinuity
if (continuous.commands.size() <= 2) return continuous;
List<Path.Command> broken = new LinkedList<>();
List<Path.Command> broken = new ArrayList<>();
double[] lens = {0, 0, 0}; //the revolving array of command lengths
for (int i = 0; i < continuous.commands.size(); i ++) {
if (i < continuous.commands.size()-1 && continuous.commands.get(i+1).type != 'M')
@ -502,7 +500,7 @@ public class SVGMap implements Iterable<SVGMap.SVGElement>, SavableImage {
if (cmd.type == 'M') { //separated by movetos
if (currentPart != null)
parts.add(currentPart);
currentPart = new LinkedList<Path.Command>();
currentPart = new ArrayList<Path.Command>();
}
else if (currentPart == null)
throw new RuntimeException(format(
@ -511,7 +509,7 @@ public class SVGMap implements Iterable<SVGMap.SVGElement>, SavableImage {
}
parts.add(currentPart);
List<Path.Command> closed = new LinkedList<Path.Command>();
List<Path.Command> closed = new ArrayList<Path.Command>();
for (int i = 0; i < parts.size(); i ++) { //now look through those parts
List<Path.Command> partI = parts.get(i);
if (partI.size() > 1

View File

@ -355,7 +355,7 @@ public abstract class Projection {
*/
public List<Path.Command> drawGraticule(double spacing, double precision, double outW, double outH,
double maxLat, double maxLon, double[] pole) {
List<Path.Command> output = new LinkedList<>();
List<Path.Command> output = new ArrayList<>();
for (int y = 0; y < (int)(maxLat/spacing); y ++) {
output.addAll(drawLoxodrome( //northern parallel