Ignore:
Timestamp:
2011-06-07T19:05:14+02:00 (13 years ago)
Author:
bastiK
Message:

memory optimizations for Node & WayPoint (Patch by Gubaer, modified)

The field 'proj' in CachedLatLon is a waste of memory. For the 2 classes where this has the greatest impact, the cache for the projected coordinates is replaced by 2 simple double fields (east & north). On projection change, they have to be invalidated explicitly. This is handled by the DataSet & the GpxLayer.

File:
1 edited

Legend:

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

    r4043 r4126  
    5252import org.openstreetmap.josm.data.coor.LatLon;
    5353import org.openstreetmap.josm.data.gpx.GpxData;
     54import org.openstreetmap.josm.data.gpx.GpxRoute;
    5455import org.openstreetmap.josm.data.gpx.GpxTrack;
    5556import org.openstreetmap.josm.data.gpx.GpxTrackSegment;
     
    5960import org.openstreetmap.josm.data.osm.Way;
    6061import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     62import org.openstreetmap.josm.data.projection.Projection;
    6163import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
    6264import org.openstreetmap.josm.gui.HelpAwareOptionPane;
     
    330332
    331333        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    332         Main.pref.getBoolean("mappaint.gpx.use-antialiasing", false) ?
    333                 RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
     334                Main.pref.getBoolean("mappaint.gpx.use-antialiasing", false) ?
     335                        RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
    334336
    335337        /****************************************************************
     
    12311233        if (bestEN == null)
    12321234            return null;
    1233         WayPoint best = new WayPoint(Main.proj.eastNorth2latlon(bestEN));
     1235        WayPoint best = new WayPoint(Main.getProjection().eastNorth2latlon(bestEN));
    12341236        best.time = bestTime;
    12351237        return best;
     
    14901492            importer.importDataHandleExceptions(files, NullProgressMonitor.INSTANCE);
    14911493        }
    1492 
     1494    }
     1495
     1496    @Override
     1497    public void projectionChanged(Projection oldValue, Projection newValue) {
     1498        if (newValue == null) return;
     1499        if (data.waypoints != null) {
     1500            for (WayPoint wp : data.waypoints){
     1501                wp.invalidateEastNorthCache();
     1502            }
     1503        }
     1504        if (data.tracks != null){
     1505            for (GpxTrack track: data.tracks) {
     1506                for (GpxTrackSegment segment: track.getSegments()) {
     1507                    for (WayPoint wp: segment.getWayPoints()) {
     1508                        wp.invalidateEastNorthCache();
     1509                    }
     1510                }
     1511            }
     1512        }
     1513        if (data.routes != null) {
     1514            for (GpxRoute route: data.routes) {
     1515                if (route.routePoints == null) {
     1516                    continue;
     1517                }
     1518                for (WayPoint wp: route.routePoints) {
     1519                    wp.invalidateEastNorthCache();
     1520                }
     1521            }
     1522        }
    14931523    }
    14941524}
Note: See TracChangeset for help on using the changeset viewer.