Changeset 6645 in josm


Ignore:
Timestamp:
2014-01-06T18:40:17+01:00 (6 years ago)
Author:
simon04
Message:

see #9414 - MapCSS validator: some performance imrovements (pre-compile regular expressions, drop regular expressions for key presence checks)

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/validator/combinations.mapcss

    r6550 r6645  
    7171*[source:height                ][!height],
    7272*[source:lanes                 ][!lanes],
    73 *[/source:(addr:)?postcode/    ][!addr:postcode],
    74 *[/source:(addr:)?housenumber/ ][!addr:housenumber],
     73*[source:postcode              ][!addr:postcode],
     74*[source:housenumber           ][!addr:housenumber],
     75*[source:addr:postcode         ][!addr:postcode],
     76*[source:addr:housenumber      ][!addr:housenumber],
    7577*[source:addr                  ][!/^addr:/],
    7678*[source:maxspeed              ][!/^maxspeed:?/] {
  • trunk/data/validator/deprecated.mapcss

    r6633 r6645  
    179179
    180180/* from http://wiki.openstreetmap.org/wiki/Conditional_restrictions#Deprecated_tags */
    181 *[/(day|date|hour)_(on|off)/][!restriction] {
     181*[day_on][!restriction],
     182*[day_off][!restriction],
     183*[date_on][!restriction],
     184*[date_off][!restriction],
     185*[hour_on][!restriction],
     186*[hour_off][!restriction] {
    182187  throwWarning: tr("{0} is deprecated", "{0.key}");
    183188  suggestAlternative: "*:conditional";
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java

    r6630 r6645  
    1616import org.openstreetmap.josm.gui.mappaint.Environment;
    1717import org.openstreetmap.josm.tools.CheckParameterUtil;
     18import org.openstreetmap.josm.tools.Predicate;
    1819import org.openstreetmap.josm.tools.Predicates;
    1920import org.openstreetmap.josm.tools.Utils;
     
    2627        switch (context) {
    2728        case PRIMITIVE:
    28             return new KeyValueCondition(k, v, op, considerValAsKey);
     29            return KeyValueRegexpCondition.SUPPORTED_OPS.contains(op) && !considerValAsKey
     30                    ? new KeyValueRegexpCondition(k, v, op, false)
     31                    : new KeyValueCondition(k, v, op, considerValAsKey);
    2932        case LINK:
    3033            if (considerValAsKey)
     
    180183        public String toString() {
    181184            return "[" + k + "'" + op + "'" + v + "]";
     185        }
     186    }
     187
     188    public static class KeyValueRegexpCondition extends KeyValueCondition {
     189
     190        public final Pattern pattern;
     191        public static final EnumSet<Op> SUPPORTED_OPS = EnumSet.of(Op.REGEX, Op.NREGEX);
     192
     193        public KeyValueRegexpCondition(String k, String v, Op op, boolean considerValAsKey) {
     194            super(k, v, op, considerValAsKey);
     195            CheckParameterUtil.ensureThat(!considerValAsKey, "considerValAsKey is not supported");
     196            CheckParameterUtil.ensureThat(SUPPORTED_OPS.contains(op), "Op must be REGEX or NREGEX");
     197            this.pattern = Pattern.compile(v);
     198        }
     199
     200        @Override
     201        public boolean applies(Environment env) {
     202            final String value = env.osm.get(k);
     203            return value != null && (op.equals(Op.REGEX)
     204                    ? pattern.matcher(value).find()
     205                    : !pattern.matcher(value).find());
    182206        }
    183207    }
     
    244268        public final boolean negateResult;
    245269        public final KeyMatchType matchType;
     270        public Predicate<String> containsPattern;
    246271
    247272        public KeyCondition(String label, boolean negateResult, KeyMatchType matchType){
     
    249274            this.negateResult = negateResult;
    250275            this.matchType = matchType;
     276            this.containsPattern = KeyMatchType.REGEX.equals(matchType)
     277                    ? Predicates.stringContainsPattern(Pattern.compile(label))
     278                    : null;
    251279        }
    252280
     
    259287                else if (KeyMatchType.FALSE.equals(matchType))
    260288                    return e.osm.isKeyFalse(label) ^ negateResult;
    261                 else if (KeyMatchType.REGEX.equals(matchType))
    262                     return Utils.exists(e.osm.keySet(), Predicates.stringContainsPattern(Pattern.compile(label))) ^ negateResult;
    263                 else
     289                else if (KeyMatchType.REGEX.equals(matchType)) {
     290                    return Utils.exists(e.osm.keySet(), containsPattern) ^ negateResult;
     291                } else {
    264292                    return e.osm.hasKey(label) ^ negateResult;
     293                }
    265294            case LINK:
    266295                Utils.ensure(false, "Illegal state: KeyCondition not supported in LINK context");
Note: See TracChangeset for help on using the changeset viewer.