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/data/osm/DataSet.java

    r4087 r4126  
    2020import java.util.concurrent.locks.ReentrantReadWriteLock;
    2121
     22import org.openstreetmap.josm.Main;
    2223import org.openstreetmap.josm.data.Bounds;
    2324import org.openstreetmap.josm.data.SelectionChangedListener;
     
    3435import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
    3536import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
     37import org.openstreetmap.josm.data.projection.Projection;
     38import org.openstreetmap.josm.data.projection.ProjectionChangeListener;
    3639import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
    3740import org.openstreetmap.josm.tools.FilteredCollection;
    3841import org.openstreetmap.josm.tools.Predicate;
    3942import org.openstreetmap.josm.tools.SubclassFilteredCollection;
     43import org.openstreetmap.josm.tools.Utils;
    4044
    4145/**
     
    8387 * @author imi
    8488 */
    85 public class DataSet implements Cloneable {
     89public class DataSet implements Cloneable, ProjectionChangeListener {
    8690
    8791    /**
     
    120124    private final ReadWriteLock lock = new ReentrantReadWriteLock();
    121125    private final Object selectionLock = new Object();
     126
     127    public DataSet() {
     128        /*
     129         * Transparently register as projection change lister. No need to explicitly remove the
     130         * the listener, projection change listeners are managed as WeakReferences.
     131         */
     132        Main.addProjectionChangeListener(this);
     133    }
    122134
    123135    public Lock getReadLock() {
     
    975987    }
    976988
     989    /**
     990     * Invalidates the internal cache of projected east/north coordinates.
     991     *
     992     * This method can be invoked after the globally configured projection method
     993     * changed. In contrast to {@link DataSet#reproject()} it only invalidates the
     994     * cache and doesn't reproject the coordinates.
     995     */
     996    public void invalidateEastNorthCache() {
     997        if (Main.getProjection() == null) return; // sanity check
     998        try {
     999            beginUpdate();
     1000            for (Node n: Utils.filteredCollection(allPrimitives, Node.class)) {
     1001                n.invalidateEastNorthCache();
     1002            }
     1003        } finally {
     1004            endUpdate();
     1005        }
     1006    }
     1007
    9771008    public void cleanupDeletedPrimitives() {
    9781009        beginUpdate();
     
    10641095        return ret;
    10651096    }
     1097
     1098    /* --------------------------------------------------------------------------------- */
     1099    /* interface ProjectionChangeListner                                                 */
     1100    /* --------------------------------------------------------------------------------- */
     1101    @Override
     1102    public void projectionChanged(Projection oldValue, Projection newValue) {
     1103        invalidateEastNorthCache();
     1104    }
    10661105}
Note: See TracChangeset for help on using the changeset viewer.