Changeset 14238 in josm


Ignore:
Timestamp:
2018-09-09T23:10:41+02:00 (2 months ago)
Author:
Don-vip
Message:

fix #16510 - improve performance of Ctrl-A by caching icons used to display OSM primitive types

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/OsmUtils.java

    r13957 r14238  
    77import java.util.Locale;
    88import java.util.Map;
    9 import java.util.Objects;
    109import java.util.Set;
    1110
     
    165164     */
    166165    public static boolean isOsmCollectionEditable(Collection<? extends IPrimitive> collection) {
    167         return collection != null && !collection.isEmpty()
    168             && collection.stream().map(IPrimitive::getDataSet).filter(Objects::nonNull).noneMatch(OsmData::isLocked);
     166        if (collection == null || collection.isEmpty()) {
     167            return false;
     168        }
     169        // see #16510: optimization: only consider the first primitive, as collection always refer to the same dataset
     170        OsmData<?, ?, ?, ?> ds = collection.iterator().next().getDataSet();
     171        return ds == null || !ds.isLocked();
    169172    }
    170173}
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r14214 r14238  
    3434import java.util.Base64;
    3535import java.util.Collection;
     36import java.util.Collections;
    3637import java.util.HashMap;
    3738import java.util.HashSet;
     
    270271    }
    271272
     273    /** small cache of critical images used in many parts of the application */
     274    private static final Map<OsmPrimitiveType, ImageIcon> osmPrimitiveTypeCache = Collections.synchronizedMap(new HashMap<>());
     275
    272276    /** directories in which images are searched */
    273277    protected Collection<String> dirs;
     
    14741478    public static ImageIcon get(OsmPrimitiveType type) {
    14751479        CheckParameterUtil.ensureParameterNotNull(type, "type");
    1476         return get("data", type.getAPIName());
     1480        return osmPrimitiveTypeCache.computeIfAbsent(type, t -> get("data", t.getAPIName()));
    14771481    }
    14781482
Note: See TracChangeset for help on using the changeset viewer.