Changeset 7055 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2014-05-03T10:41:01+02:00 (11 years ago)
Author:
bastiK
Message:

mapcss: optimisation by adding an extra class for the most common type of condition (see #9691)

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r7033 r7055  
    232232                final Tag tag = c instanceof Condition.KeyCondition
    233233                        ? ((Condition.KeyCondition) c).asTag()
     234                        : c instanceof Condition.SimpleKeyValueCondition
     235                        ? ((Condition.SimpleKeyValueCondition) c).asTag()
    234236                        : c instanceof Condition.KeyValueCondition
    235237                        ? ((Condition.KeyValueCondition) c).asTag()
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java

    r7012 r7055  
    2929        switch (context) {
    3030        case PRIMITIVE:
    31             return KeyValueRegexpCondition.SUPPORTED_OPS.contains(op) && !considerValAsKey
    32                     ? new KeyValueRegexpCondition(k, v, op, false)
    33                     : new KeyValueCondition(k, v, op, considerValAsKey);
     31            if (KeyValueRegexpCondition.SUPPORTED_OPS.contains(op) && !considerValAsKey)
     32                return new KeyValueRegexpCondition(k, v, op, false);
     33            if (!considerValAsKey && op.equals(Op.EQ))
     34                return new SimpleKeyValueCondition(k, v);
     35            return new KeyValueCondition(k, v, op, considerValAsKey);
    3436        case LINK:
    3537            if (considerValAsKey)
     
    150152
    151153    /**
     154     * Most common case of a KeyValueCondition.
     155     *
     156     * Extra class for performance reasons.
     157     */
     158    public static class SimpleKeyValueCondition extends Condition {
     159        public final String k;
     160        public final String v;
     161
     162        public SimpleKeyValueCondition(String k, String v) {
     163            this.k = k;
     164            this.v = v;
     165        }
     166
     167        @Override
     168        public boolean applies(Environment e) {
     169            return v.equals(e.osm.get(k));
     170        }
     171       
     172        public Tag asTag() {
     173            return new Tag(k, v);
     174        }
     175    }
     176
     177    /**
    152178     * <p>Represents a key/value condition which is either applied to a primitive.</p>
    153179     *
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    r7054 r7055  
    525525            return subpart;
    526526        }
     527
    527528        @Override
    528529        public Range getRange() {
Note: See TracChangeset for help on using the changeset viewer.