Changeset 4621 in josm for trunk/src/org


Ignore:
Timestamp:
2011-11-29T21:25:55+01:00 (9 years ago)
Author:
Don-vip
Message:

fix #6987 - Crashing on osm file open -> Fix a performance problem with very large multipolygons loaded thousands of times

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r4480 r4621  
    5151import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
    5252import org.openstreetmap.josm.gui.layer.markerlayer.PlayHeadMarker;
     53import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    5354import org.openstreetmap.josm.tools.AudioPlayer;
    5455import org.openstreetmap.josm.tools.BugReportExceptionHandler;
     
    842843        Main.pref.removePreferenceChangeListener(this);
    843844        DataSet.removeSelectionListener(repaintSelectionChangedListener);
     845        MapPaintStyles.getStyles().clearMultipolygonsCache(this);
    844846    }
    845847
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r4606 r4621  
    66import java.util.Collection;
    77import java.util.Collections;
     8import java.util.HashMap;
    89import java.util.Iterator;
    910import java.util.List;
     11import java.util.Map;
    1012import java.util.Map.Entry;
    1113
     
    2830    private boolean defaultNodes, defaultLines;
    2931    private int defaultNodesIdx, defaultLinesIdx;
     32   
     33    private final Map<NavigatableComponent, Map<Relation, Multipolygon>> multipolygonsCache;
    3034
    3135    public ElemStyles()
    3236    {
    3337        styleSources = new ArrayList<StyleSource>();
     38        multipolygonsCache = new HashMap<NavigatableComponent, Map<Relation,Multipolygon>>();
    3439    }
    3540
     
    116121    }
    117122
     123    private final Multipolygon getCachedMultipolygon(NavigatableComponent nc, Relation r) {
     124        Multipolygon multipolygon = null;
     125        Map<Relation, Multipolygon> map = multipolygonsCache.get(nc);
     126        if (map == null) {
     127            multipolygonsCache.put(nc, map = new HashMap<Relation, Multipolygon>());
     128        }
     129        multipolygon = map.get(r);
     130        if (multipolygon == null) {
     131            map.put(r, multipolygon = new Multipolygon(nc));
     132            multipolygon.load(r);
     133        }
     134        return multipolygon;
     135    }
     136   
    118137    /**
    119138     * Create the list of styles and its valid scale range for one primitive.
     
    160179                    continue;
    161180                }
    162                 Multipolygon multipolygon = new Multipolygon(nc);
    163                 multipolygon.load(r);
     181                Multipolygon multipolygon = getCachedMultipolygon(nc, r);
    164182
    165183                if (multipolygon.getOuterWays().contains(osm)) {
     
    226244                    continue;
    227245                }
    228                 Multipolygon multipolygon = new Multipolygon(nc);
    229                 multipolygon.load(ref);
     246                final Multipolygon multipolygon = getCachedMultipolygon(nc, ref);
    230247
    231248                if (multipolygon.getInnerWays().contains(osm)) {
     
    413430    }
    414431
     432    public void clearMultipolygonsCache(NavigatableComponent nc) {
     433        multipolygonsCache.remove(nc);
     434    }
    415435}
Note: See TracChangeset for help on using the changeset viewer.