Ignore:
Timestamp:
2017-05-03T11:19:04+02:00 (7 years ago)
Author:
bastiK
Message:

applied #13956 - memory optimization with presets cache (patch by GerdP)

File:
1 edited

Legend:

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

    r11942 r12042  
    6969    /** Normalized keys: the key should be substituted by the value if the key was not found in presets */
    7070    private static final Map<String, String> harmonizedKeys = new HashMap<>();
    71     /** The spell check preset values */
    72     private static volatile MultiMap<String, String> presetsValueData;
     71    /** The spell check preset values which are not stored in TaggingPresets */
     72    private static volatile MultiMap<String, String> additionalPresetsValueData;
    7373    /** The TagChecker data */
    7474    private static final List<CheckerData> checkerData = new ArrayList<>();
     
    259259        Collection<TaggingPreset> presets = TaggingPresets.getTaggingPresets();
    260260        if (!presets.isEmpty()) {
    261             presetsValueData = new MultiMap<>();
     261            additionalPresetsValueData = new MultiMap<>();
    262262            for (String a : OsmPrimitive.getUninterestingKeys()) {
    263                 presetsValueData.putVoid(a);
     263                additionalPresetsValueData.putVoid(a);
    264264            }
    265265            // TODO directionKeys are no longer in OsmPrimitive (search pattern is used instead)
    266266            for (String a : Main.pref.getCollection(ValidatorPreference.PREFIX + ".knownkeys",
    267267                    Arrays.asList(new String[]{"is_in", "int_ref", "fixme", "population"}))) {
    268                 presetsValueData.putVoid(a);
     268                additionalPresetsValueData.putVoid(a);
    269269            }
    270270            for (TaggingPreset p : presets) {
     
    285285        Collection<String> values = ky.getValues();
    286286        if (ky.key != null && values != null) {
    287             presetsValueData.putAll(ky.key, values);
    288287            harmonizedKeys.put(harmonizeKey(ky.key), ky.key);
    289288        }
     
    305304    }
    306305
     306    private static Set<String> getPresetValues(String key) {
     307        Set<String> res = TaggingPresets.getPresetValues(key);
     308        if (res != null)
     309            return res;
     310        return additionalPresetsValueData.get(key);
     311    }
     312
    307313    /**
    308314     * Determines if the given key is in internal presets.
     
    312318     */
    313319    public static boolean isKeyInPresets(String key) {
    314         return presetsValueData.get(key) != null;
     320        return getPresetValues(key) != null;
    315321    }
    316322
     
    323329     */
    324330    public static boolean isTagInPresets(String key, String value) {
    325         final Set<String> values = presetsValueData.get(key);
     331        final Set<String> values = getPresetValues(key);
    326332        return values != null && (values.isEmpty() || values.contains(value));
    327333    }
     
    462468                withErrors.put(p, "HTML");
    463469            }
    464             if (checkValues && key != null && value != null && !value.isEmpty() && presetsValueData != null && !isTagIgnored(key, value)) {
     470            if (checkValues && key != null && value != null && !value.isEmpty() && additionalPresetsValueData != null
     471                    && !isTagIgnored(key, value)) {
    465472                if (!isKeyInPresets(key)) {
    466473                    String prettifiedKey = harmonizeKey(key);
     
    487494                    // try to fix common typos and check again if value is still unknown
    488495                    String fixedValue = harmonizeValue(prop.getValue());
    489                     Map<String, String> possibleValues = getPossibleValues(presetsValueData.get(key));
     496                    Map<String, String> possibleValues = getPossibleValues(getPresetValues(key));
    490497                    if (possibleValues.containsKey(fixedValue)) {
    491498                        final String newKey = possibleValues.get(fixedValue);
Note: See TracChangeset for help on using the changeset viewer.