Changeset 6106 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2013-08-03T00:21:50+02:00 (11 years ago)
Author:
Don-vip
Message:

see #8902 - Small performance enhancements / coding style (patch by shinigami):

  • set init size for lists when obvious
Location:
trunk/src/org/openstreetmap/josm
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java

    r6084 r6106  
    154154                unreversedTagWays.removeAll(reversedWays);
    155155                ReverseWayTagCorrector reverseWayTagCorrector = new ReverseWayTagCorrector();
    156                 List<Way> reversedTagWays = new ArrayList<Way>();
     156                List<Way> reversedTagWays = new ArrayList<Way>(reversedWays.size());
    157157                Collection<Command> changePropertyCommands =  null;
    158158                for (Way w : reversedWays) {
     
    497497
    498498        protected Set<Node> getNodes(Stack<NodePair> pairs) {
    499             HashSet<Node> nodes = new LinkedHashSet<Node>();
     499            HashSet<Node> nodes = new LinkedHashSet<Node>(2*pairs.size());
    500500            for (NodePair pair: pairs) {
    501501                nodes.add(pair.getA());
     
    517517
    518518        protected Set<Node> getNodes() {
    519             Set<Node> nodes = new LinkedHashSet<Node>();
     519            Set<Node> nodes = new LinkedHashSet<Node>(2 * edges.size());
    520520            for (NodePair pair: edges) {
    521521                nodes.add(pair.getA());
  • trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java

    r6093 r6106  
    137137
    138138            // build a way for the circle
    139             List<Node> wayToAdd = new ArrayList<Node>();
     139            List<Node> wayToAdd = new ArrayList<Node>(numberOfNodesInCircle + 1);
    140140
    141141            for (int i = 1; i <= numberOfNodesInCircle; i++) {
  • trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java

    r6069 r6106  
    263263    public static boolean pasteTagsFromText(Collection<OsmPrimitive> selection, String text) {
    264264        Map<String, String> tags = TextTagParser.readTagsFromText(text);
    265         List<Command> commands = new ArrayList<Command>();
    266265        if (tags==null || tags.isEmpty()) {
    267266            TextTagParser.showBadBufferMessage(help);
     
    269268        }
    270269        if (!TextTagParser.validateTags(tags)) return false;
     270
     271        List<Command> commands = new ArrayList<Command>(tags.size());
    271272        String v;
    272273        for (String key: tags.keySet()) {
  • trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java

    r6084 r6106  
    103103            searchHistory.removeLast();
    104104        }
    105         List<String> savedHistory = new ArrayList<String>();
     105        List<String> savedHistory = new ArrayList<String>(searchHistory.size());
    106106        for (SearchSetting item: searchHistory) {
    107107            savedHistory.add(item.writeToString());
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r6104 r6106  
    202202            return null;
    203203        else {
    204             List<PseudoCommand> children = new ArrayList<PseudoCommand>();
     204            List<PseudoCommand> children = new ArrayList<PseudoCommand>(toDelete.size());
    205205            for (final OsmPrimitive osm : toDelete) {
    206206                children.add(new PseudoCommand() {
  • trunk/src/org/openstreetmap/josm/data/validation/tests/SimilarNamedWays.java

    r6085 r6106  
    8080                int levenshteinDistance = getLevenshteinDistance(name, name2);
    8181                if (0 < levenshteinDistance && levenshteinDistance <= 2) {
    82                     List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>();
     82                    List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(2);
    8383                    primitives.add(w);
    8484                    primitives.add(w2);
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java

    r5920 r6106  
    245245            LatLon topLeft  = new LatLon(y2+fudge, x1-fudge);
    246246            LatLon botRight = new LatLon(y1-fudge, x2+fudge);
    247             List<LatLon> ret = new ArrayList<LatLon>();
     247            List<LatLon> ret = new ArrayList<LatLon>(2);
    248248            ret.add(topLeft);
    249249            ret.add(botRight);
  • trunk/src/org/openstreetmap/josm/gui/MapStatus.java

    r6101 r6106  
    313313                                        // These labels may need to be updated from the outside
    314314                                        // so collect them
    315                                         List<JLabel> lbls = new ArrayList<JLabel>();
     315                                        List<JLabel> lbls = new ArrayList<JLabel>(osms.size());
    316316                                        for (final OsmPrimitive osm : osms) {
    317317                                            JLabel l = popupBuildPrimitiveLabels(osm);
  • trunk/src/org/openstreetmap/josm/gui/io/CloseChangesetDialog.java

    r6084 r6106  
    214214    public Collection<Changeset> getSelectedChangesets() {
    215215        Object [] sel = lstOpenChangesets.getSelectedValues();
    216         ArrayList<Changeset> ret = new ArrayList<Changeset>();
     216        ArrayList<Changeset> ret = new ArrayList<Changeset>(sel.length);
    217217        for (Object o: sel) {
    218218            ret.add((Changeset)o);
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

    r6104 r6106  
    290290            panelTf.add(new JLabel(tr("I am in the timezone of: ")), gc);
    291291
    292             Vector<String> vtTimezones = new Vector<String>();
    293292            String[] tmp = TimeZone.getAvailableIDs();
     293            Vector<String> vtTimezones = new Vector<String>(tmp.length);
    294294
    295295            for (String tzStr : tmp) {
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

    r6093 r6106  
    837837
    838838    public List<ImageEntry> getImages() {
    839         List<ImageEntry> copy = new ArrayList<ImageEntry>();
     839        List<ImageEntry> copy = new ArrayList<ImageEntry>(data.size());
    840840        for (ImageEntry ie : data) {
    841841            copy.add(ie.clone());
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r6087 r6106  
    15311531
    15321532        public boolean put(Collection<? extends SourceEntry> entries) {
    1533             Collection<Map<String, String>> setting = new ArrayList<Map<String, String>>();
     1533            Collection<Map<String, String>> setting = new ArrayList<Map<String, String>>(entries.size());
    15341534            for (SourceEntry e : entries) {
    15351535                setting.add(serialize(e));
  • trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java

    r6070 r6106  
    202202
    203203    private List<LayerDetails> parseLayers(List<Element> children, Set<String> parentCrs) {
    204         List<LayerDetails> details = new ArrayList<LayerDetails>();
     204        List<LayerDetails> details = new ArrayList<LayerDetails>(children.size());
    205205        for (Element element : children) {
    206206            details.add(parseLayer(element, parentCrs));
Note: See TracChangeset for help on using the changeset viewer.