Changeset 3129 in josm


Ignore:
Timestamp:
2010-03-13T15:34:25+01:00 (15 years ago)
Author:
jttt
Message:

Memory optimizations

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r3116 r3129  
    5555    private static final int FLAG_TAGGED = 1 << 6;
    5656    private static final int FLAG_DIRECTION_REVERSED = 1 << 7;
     57    private static final int FLAG_HIGHLIGHTED = 1 << 8;
     58    private static final int FLAG_INCOMPLETE = 1 << 9;
    5759
    5860    /**
     
    119121    /* mappaint data */
    120122    public ElemStyle mappaintStyle = null;
    121     public Integer mappaintDrawnCode = 0;
     123    public int mappaintDrawnCode = 0;
    122124
    123125    /* This should not be called from outside. Fixing the UI to add relevant
     
    168170    }
    169171
    170     private volatile byte flags = FLAG_VISIBLE;   // visible per default
     172    private volatile short flags = FLAG_VISIBLE;   // visible per default
    171173
    172174    /**
     
    175177     */
    176178    private User user = null;
    177 
    178     /**
    179      * If set to true, this object is incomplete, which means only the id
    180      * and type is known (type is the objects instance class)
    181      */
    182     private boolean incomplete = false;
    183179
    184180    /**
     
    333329     */
    334330    public boolean isUsable() {
    335         return !isDeleted() && !isIncomplete() && !isDisabled();
    336     }
    337 
    338     public boolean isDrawable()
    339     {
    340         return !isDeleted() && !isIncomplete() && !isFiltered();
     331        return (flags & (FLAG_DELETED + FLAG_INCOMPLETE + FLAG_DISABLED)) == 0;
     332    }
     333
     334    public boolean isDrawable() {
     335        return (flags & (FLAG_DELETED + FLAG_INCOMPLETE + FLAG_FILTERED)) == 0;
    341336    }
    342337
     
    470465        return timestamp == 0;
    471466    }
    472 
    473     /**
    474      * If set to true, this object is highlighted. Currently this is only used to
    475      * show which ways/nodes will connect
    476      */
    477     private volatile boolean highlighted = false;
    478467
    479468    private int timestamp;
     
    12701259    }
    12711260
     1261    /**
     1262     * If set to true, this object is incomplete, which means only the id
     1263     * and type is known (type is the objects instance class)
     1264     */
    12721265    private void setIncomplete(boolean incomplete) {
    1273         if (dataSet != null && incomplete != this.incomplete) {
     1266        if (dataSet != null && incomplete != this.isIncomplete()) {
    12741267            if (incomplete) {
    12751268                dataSet.firePrimitivesRemoved(Collections.singletonList(this), true);
     
    12781271            }
    12791272        }
    1280         this.incomplete = incomplete;
     1273        if (incomplete) {
     1274            flags |= FLAG_INCOMPLETE;
     1275        } else {
     1276            flags &= ~FLAG_INCOMPLETE;
     1277        }
    12811278    }
    12821279
    12831280    public boolean isIncomplete() {
    1284         return incomplete;
     1281        return (flags & FLAG_INCOMPLETE) != 0;
    12851282    }
    12861283
     
    12901287
    12911288    public void setHighlighted(boolean highlighted) {
    1292         if (this.highlighted != highlighted) {
    1293             this.highlighted = highlighted;
     1289        if (isHighlighted() != highlighted) {
     1290            if (highlighted) {
     1291                flags |= FLAG_HIGHLIGHTED;
     1292            } else {
     1293                flags &= ~FLAG_HIGHLIGHTED;
     1294            }
    12941295            if (dataSet != null) {
    12951296                dataSet.fireHighlightingChanged(this);
     
    12991300
    13001301    public boolean isHighlighted() {
    1301         return highlighted;
     1302        return (flags & FLAG_HIGHLIGHTED) != 0;
    13021303    }
    13031304}
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r2971 r3129  
    3232import org.openstreetmap.josm.data.osm.RelationMember;
    3333import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
     34import org.openstreetmap.josm.data.osm.Storage;
    3435import org.openstreetmap.josm.data.osm.User;
    3536import org.openstreetmap.josm.data.osm.Way;
     
    119120        private long currentExternalId;
    120121        private String generator;
     122        private Storage<String> internedStrings = new Storage<String>();
     123
     124        // Memory optimization - see #2312
     125        private String intern(String s) {
     126            String result = internedStrings.get(s);
     127            if (result == null) {
     128                internedStrings.put(s);
     129                return s;
     130            } else
     131                return result;
     132        }
    121133
    122134        @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
     135
    123136            if (qName.equals("osm")) {
    124137                if (atts == null) {
     
    258271                String key = atts.getValue("k");
    259272                String value = atts.getValue("v");
    260                 currentPrimitive.put(key, value);
     273                currentPrimitive.put(intern(key), intern(value));
     274
    261275            } else {
    262276                System.out.println(tr("Undefined element ''{0}'' found in input stream. Skipping.", qName));
Note: See TracChangeset for help on using the changeset viewer.