Changeset 2656 in josm


Ignore:
Timestamp:
2009-12-19T11:39:23+01:00 (15 years ago)
Author:
jttt
Message:

Optimalization of two hotspots found by profiler. Makes drawing in large dataset much faster.

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r2655 r2656  
    305305     */
    306306    public Collection<Node> getSelectedNodes() {
    307         return getSelected(nodes);
     307        List<Node> result = new ArrayList<Node>(selectedPrimitives.size());
     308        for (OsmPrimitive primitive:selectedPrimitives) {
     309            if (primitive instanceof Node) {
     310                result.add((Node)primitive);
     311            }
     312        }
     313        return result;
    308314    }
    309315
     
    312318     */
    313319    public Collection<Way> getSelectedWays() {
    314         return getSelected(ways);
     320        List<Way> result = new ArrayList<Way>(selectedPrimitives.size());
     321        for (OsmPrimitive primitive:selectedPrimitives) {
     322            if (primitive instanceof Way) {
     323                result.add((Way)primitive);
     324            }
     325        }
     326        return result;
    315327    }
    316328
     
    319331     */
    320332    public Collection<Relation> getSelectedRelations() {
    321         return getSelected(relations);
    322     }
    323 
    324     /**
    325      * Return all selected items in the collection.
    326      * @param list The collection from which the selected items are returned.
    327      */
    328     private <T extends OsmPrimitive> Collection<T> getSelected(Collection<T> list) {
    329         if (list == null)
    330             return new LinkedList<T>();
    331         // getSelected() is called with large lists, so
    332         // creating the return list from the selection
    333         // should be faster most of the time.
    334         Collection<T> sel = new LinkedHashSet<T>(list);
    335         sel.retainAll(selectedPrimitives);
    336         return sel;
     333        List<Relation> result = new ArrayList<Relation>(selectedPrimitives.size() / 10);
     334        for (OsmPrimitive primitive:selectedPrimitives) {
     335            if (primitive instanceof Relation) {
     336                result.add((Relation)primitive);
     337            }
     338        }
     339        return result;
    337340    }
    338341
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r2655 r2656  
    679679     */
    680680    @Override public final int hashCode() {
    681         final int[] ret = new int[1];
    682         Visitor v = new Visitor(){
    683             public void visit(Node n) { ret[0] = 0; }
    684             public void visit(Way w) { ret[0] = 1; }
    685             public void visit(Relation e) { ret[0] = 2; }
    686             public void visit(Changeset cs) { ret[0] = 3; }
    687         };
    688         visit(v);
    689         return (int)(id<<2)+ret[0];
     681        return (int)id;
    690682    }
    691683
Note: See TracChangeset for help on using the changeset viewer.