Ignore:
Timestamp:
2011-06-07T19:05:14+02:00 (8 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.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/coor/CachedLatLon.java

    r3253 r4126  
    55import org.openstreetmap.josm.data.projection.Projection;
    66
     7/**
     8 * LatLon class that maintains a cache of projected EastNorth coordinates.
     9 *
     10 * This class is convenient to use, but has relatively high memory costs.
     11 * It keeps a pointer to the last known projection in order to detect projection
     12 * changes.
     13 *
     14 * Node and WayPoint have another, optimized, cache for projected coordinates.
     15 */
    716public class CachedLatLon extends LatLon {
    817    private EastNorth eastNorth;
     
    1928
    2029    public CachedLatLon(EastNorth eastNorth) {
    21         super(Main.proj.eastNorth2latlon(eastNorth));
    22         proj = Main.proj;
     30        super(Main.getProjection().eastNorth2latlon(eastNorth));
     31        proj = Main.getProjection();
    2332        this.eastNorth = eastNorth;
    2433    }
     
    3039
    3140    public final void setEastNorth(EastNorth eastNorth) {
    32         proj = Main.proj;
     41        proj = Main.getProjection();
    3342        this.eastNorth = eastNorth;
    3443        LatLon l = proj.eastNorth2latlon(eastNorth);
     
    3645    }
    3746
     47    /**
     48     * Replies the projected east/north coordinates.
     49     *
     50     * @return the internally cached east/north coordinates. null, if the globally defined projection is null
     51     */
    3852    public final EastNorth getEastNorth() {
    39         if(proj != Main.proj)
     53        if(proj != Main.getProjection())
    4054        {
    41             proj = Main.proj;
     55            proj = Main.getProjection();
    4256            eastNorth = proj.latlon2eastNorth(this);
    4357        }
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r3656 r4126  
    106106        case DEGREES_MINUTES_SECONDS: return dms(y) + ((y < 0) ? SOUTH : NORTH);
    107107        case NAUTICAL: return dm(y) + ((y < 0) ? SOUTH : NORTH);
    108         case EAST_NORTH: return cDdFormatter.format(Main.proj.latlon2eastNorth(this).north());
     108        case EAST_NORTH: return cDdFormatter.format(Main.getProjection().latlon2eastNorth(this).north());
    109109        default: return "ERR";
    110110        }
     
    122122        case DEGREES_MINUTES_SECONDS: return dms(x) + ((x < 0) ? WEST : EAST);
    123123        case NAUTICAL: return dm(x) + ((x < 0) ? WEST : EAST);
    124         case EAST_NORTH: return cDdFormatter.format(Main.proj.latlon2eastNorth(this).east());
     124        case EAST_NORTH: return cDdFormatter.format(Main.getProjection().latlon2eastNorth(this).east());
    125125        default: return "ERR";
    126126        }
     
    142142     */
    143143    public boolean isOutSideWorld() {
    144         Bounds b = Main.proj.getWorldBoundsLatLon();
     144        Bounds b = Main.getProjection().getWorldBoundsLatLon();
    145145        return lat() < b.getMin().lat() || lat() > b.getMax().lat() ||
    146146        lon() < b.getMin().lon() || lon() > b.getMax().lon();
Note: See TracChangeset for help on using the changeset viewer.