Changeset 18275 in josm for trunk/src/org


Ignore:
Timestamp:
2021-10-13T15:26:32+02:00 (3 years ago)
Author:
GerdP
Message:

fix #20514: Possible poor performance when validating selection

  • Improve performance of validator when a small selection is tested (selected objects or on upload) and there are objects with large bboxes which cover a lot of objects
Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

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

    r18211 r18275  
    6161    private final Map<MapCSSRule, MapCSSTagCheckerAndRule> ruleToCheckMap = new HashMap<>();
    6262    private static final Map<IPrimitive, Area> mpAreaCache = new HashMap<>();
     63    private static final Set<IPrimitive> toMatchForSurrounding = new HashSet<>();
    6364    static final boolean ALL_TESTS = true;
    6465    static final boolean ONLY_SELECTED_TESTS = false;
     
    161162        }
    162163
    163         Environment env = new Environment(p, new MultiCascade(), Environment.DEFAULT_LAYER, null);
     164        final Environment env = new Environment(p, new MultiCascade(), Environment.DEFAULT_LAYER, null);
    164165        env.mpAreaCache = mpAreaCache;
     166        env.toMatchForSurrounding = toMatchForSurrounding;
    165167
    166168        Iterator<MapCSSRule> candidates = indexData.getRuleCandidates(p);
     
    220222        final Environment env = new Environment(p, new MultiCascade(), Environment.DEFAULT_LAYER, null);
    221223        env.mpAreaCache = mpAreaCache;
     224        env.toMatchForSurrounding = toMatchForSurrounding;
    222225        for (Set<MapCSSTagCheckerRule> schecks : checksCol) {
    223226            for (MapCSSTagCheckerRule check : schecks) {
     
    369372        mpAreaCache.clear();
    370373        ruleToCheckMap.clear();
     374        toMatchForSurrounding.clear();
    371375        super.endTest();
    372376    }
     
    388392
    389393        mpAreaCache.clear();
     394        toMatchForSurrounding.clear();
    390395
    391396        Set<OsmPrimitive> surrounding = new HashSet<>();
     
    468473        }
    469474
     475        toMatchForSurrounding.clear();
     476        toMatchForSurrounding.addAll(tested);
    470477        for (OsmPrimitive p : surrounding) {
    471478            if (tested.contains(p))
  • trunk/src/org/openstreetmap/josm/gui/mappaint/Environment.java

    r17744 r18275  
    8787     */
    8888    public Map<IPrimitive, Area> mpAreaCache;
     89
     90    /**
     91     * Can be null, may contain primitives when surrounding objects of the primitives are tested
     92     */
     93    public Set<IPrimitive> toMatchForSurrounding;
    8994
    9095    /**
     
    141146        this.crossingWaysMap = other.crossingWaysMap;
    142147        this.mpAreaCache = other.mpAreaCache;
     148        this.toMatchForSurrounding = other.toMatchForSurrounding;
    143149    }
    144150
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    r18208 r18275  
    378378                    toIgnore = null;
    379379                }
    380 
     380                boolean filterWithTested = e.toMatchForSurrounding != null && !e.toMatchForSurrounding.isEmpty();
    381381                for (IPrimitive p : primitives) {
     382                    if (filterWithTested && !e.toMatchForSurrounding.contains(p))
     383                        continue;
    382384                    if (isPrimitiveUsable(p) && Objects.equals(layer, OsmUtils.getLayer(p))
    383385                            && left.matches(new Environment(p).withParent(e.osm)) && isArea(p)
Note: See TracChangeset for help on using the changeset viewer.