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

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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.