Changeset 18482 in josm for trunk


Ignore:
Timestamp:
2022-06-09T15:00:28+02:00 (23 months ago)
Author:
taylor.smock
Message:

VectorDataSet: Fix MT_CORRECTNESS issues

This was most likely caused by using Collections.synchronizedCollection
initially, and then switching to a ConcurrentHashMap.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/vector/VectorDataSet.java

    r18193 r18482  
    165165    @Override
    166166    public void clear() {
    167         synchronized (this.dataStoreMap) {
    168             this.dataStoreMap.clear();
    169         }
     167        this.dataStoreMap.clear();
    170168    }
    171169
     
    533531        nearestZoom[0] = zoom;
    534532        // Create a new list to avoid concurrent modification issues
    535         synchronized (this.dataStoreMap) {
    536             final int[] keys = new ArrayList<>(this.dataStoreMap.keySet()).stream().filter(Objects::nonNull)
    537               .mapToInt(Integer::intValue).sorted().toArray();
    538             final int index;
    539             if (this.dataStoreMap.containsKey(zoom)) {
    540                 index = Arrays.binarySearch(keys, zoom);
    541             } else {
    542                 // (-(insertion point) - 1) = return -> insertion point = -(return + 1)
    543                 index = -(Arrays.binarySearch(keys, zoom) + 1);
    544             }
    545             if (index > 0) {
    546                 nearestZoom[1] = keys[index - 1];
    547             }
    548             if (index < keys.length - 2) {
    549                 nearestZoom[2] = keys[index + 1];
    550             }
    551 
    552             // TODO cleanup zooms for memory
    553         }
     533        final int[] keys = new ArrayList<>(this.dataStoreMap.keySet()).stream().filter(Objects::nonNull)
     534          .mapToInt(Integer::intValue).sorted().toArray();
     535        final int index;
     536        if (this.dataStoreMap.containsKey(zoom)) {
     537            index = Arrays.binarySearch(keys, zoom);
     538        } else {
     539            // (-(insertion point) - 1) = return -> insertion point = -(return + 1)
     540            index = -(Arrays.binarySearch(keys, zoom) + 1);
     541        }
     542        if (index > 0) {
     543            nearestZoom[1] = keys[index - 1];
     544        }
     545        if (index < keys.length - 2) {
     546            nearestZoom[2] = keys[index + 1];
     547        }
     548
     549        // TODO cleanup zooms for memory
    554550    }
    555551
Note: See TracChangeset for help on using the changeset viewer.