Changeset 15991 in josm


Ignore:
Timestamp:
2020-03-01T23:36:13+01:00 (3 months ago)
Author:
simon04
Message:

see #18802 - MapCSSStyleIndex: reuse rule if base is the same

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleIndex.java

    r15989 r15991  
    55
    66import java.text.MessageFormat;
     7import java.util.Collections;
    78import java.util.Iterator;
    89import java.util.Map;
     10import java.util.Set;
    911import java.util.stream.Collectors;
    1012import java.util.stream.Stream;
     
    7274        // optimization: filter rules for different primitive types
    7375        ruleStream.forEach(rule -> {
    74             final Map<String, MapCSSRule> selectorsByBase = rule.selectors.stream()
    75                     .collect(Collectors.groupingBy(Selector::getBase,
    76                             Collectors.collectingAndThen(Collectors.toList(), selectors -> new MapCSSRule(selectors, rule.declaration))));
     76            final Map<String, MapCSSRule> selectorsByBase;
     77            final Set<String> bases = rule.selectors.stream().map(Selector::getBase).collect(Collectors.toSet());
     78            if (bases.size() == 1) {
     79                // reuse rule
     80                selectorsByBase = Collections.singletonMap(bases.iterator().next(), rule);
     81            } else {
     82                selectorsByBase = rule.selectors.stream()
     83                        .collect(Collectors.groupingBy(Selector::getBase,
     84                                Collectors.collectingAndThen(Collectors.toList(), selectors -> new MapCSSRule(selectors, rule.declaration))));
     85            }
    7786            selectorsByBase.forEach((base, optRule) -> {
    7887                switch (base) {
Note: See TracChangeset for help on using the changeset viewer.