Changeset 16080 in josm for trunk/src/org


Ignore:
Timestamp:
2020-03-08T14:57:23+01:00 (5 years ago)
Author:
simon04
Message:

see #18886 - AbstractReader.parseTimestamp: use LRU cache

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/RecentTagCollection.java

    r13992 r16080  
    44import java.util.ArrayList;
    55import java.util.Iterator;
    6 import java.util.LinkedHashMap;
    76import java.util.List;
    87import java.util.Map;
     
    1312import org.openstreetmap.josm.data.osm.search.SearchSetting;
    1413import org.openstreetmap.josm.data.preferences.ListProperty;
     14import org.openstreetmap.josm.gui.util.LruCache;
    1515import org.openstreetmap.josm.tools.Logging;
    1616
     
    1919 */
    2020class RecentTagCollection {
    21 
    22     /**
    23      * LRU cache for recently added tags (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html)
    24      */
    25     static final class LruCache extends LinkedHashMap<Tag, Void> {
    26         private static final long serialVersionUID = 1L;
    27         private final int capacity;
    28 
    29         LruCache(int capacity) {
    30             super(capacity + 1, 1.1f, true);
    31             this.capacity = capacity;
    32         }
    33 
    34         @Override
    35         protected boolean removeEldestEntry(Map.Entry<Tag, Void> eldest) {
    36             return size() > capacity;
    37         }
    38     }
    3921
    4022    private final Map<Tag, Void> recentTags;
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r15824 r16080  
    2929import java.util.HashMap;
    3030import java.util.HashSet;
    31 import java.util.LinkedHashMap;
    3231import java.util.List;
    3332import java.util.Map;
     
    119118import org.openstreetmap.josm.gui.progress.swing.PleaseWaitProgressMonitor;
    120119import org.openstreetmap.josm.gui.util.GuiHelper;
     120import org.openstreetmap.josm.gui.util.LruCache;
    121121import org.openstreetmap.josm.gui.widgets.FileChooserManager;
    122122import org.openstreetmap.josm.gui.widgets.JosmTextArea;
     
    182182
    183183    /** List of recent relations */
    184     private final Map<Relation, Void> recentRelations = new LruCache(PROPERTY_RECENT_RELATIONS_NUMBER.get()+1);
     184    private final Map<Relation, Void> recentRelations = new LruCache<>(PROPERTY_RECENT_RELATIONS_NUMBER.get());
    185185
    186186    /**
     
    257257    static String createLayerName(Object arg) {
    258258        return tr("Data Layer {0}", arg);
    259     }
    260 
    261     static final class LruCache extends LinkedHashMap<Relation, Void> {
    262         private static final long serialVersionUID = 1L;
    263         LruCache(int initialCapacity) {
    264             super(initialCapacity, 1.1f, true);
    265         }
    266 
    267         @Override
    268         protected boolean removeEldestEntry(Map.Entry<Relation, Void> eldest) {
    269             return size() > PROPERTY_RECENT_RELATIONS_NUMBER.get();
    270         }
    271259    }
    272260
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItem.java

    r16042 r16080  
    99import java.util.Collection;
    1010import java.util.EnumSet;
    11 import java.util.LinkedHashMap;
    1211import java.util.List;
    1312import java.util.Map;
     
    2423import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
    2524import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
     25import org.openstreetmap.josm.gui.util.LruCache;
    2626import org.openstreetmap.josm.spi.preferences.Config;
    2727import org.openstreetmap.josm.tools.ImageProvider;
     
    3535public abstract class TaggingPresetItem {
    3636
    37     // cache the parsing of types using a LRU cache (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html)
    38     private static final Map<String, Set<TaggingPresetType>> TYPE_CACHE = new LinkedHashMap<>(16, 1.1f, true);
     37    // cache the parsing of types using a LRU cache
     38    private static final Map<String, Set<TaggingPresetType>> TYPE_CACHE = new LruCache<>(16);;
    3939
    4040    protected void initAutoCompletionField(AutoCompletingTextField field, String... key) {
  • trunk/src/org/openstreetmap/josm/io/AbstractReader.java

    r15820 r16080  
    4242import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    4343import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     44import org.openstreetmap.josm.gui.util.LruCache;
    4445import org.openstreetmap.josm.tools.CheckParameterUtil;
    4546import org.openstreetmap.josm.tools.Logging;
     
    421422    }
    422423
     424    private final Map<String, Integer> timestampCache = new LruCache<>(30);
     425
    423426    protected final void parseTimestamp(PrimitiveData current, String time) {
    424427        if (time != null && !time.isEmpty()) {
    425             current.setRawTimestamp((int) (DateUtils.tsFromString(time)/1000));
     428            int timestamp = timestampCache.computeIfAbsent(time, t -> (int) (DateUtils.tsFromString(t) / 1000));
     429            current.setRawTimestamp(timestamp);
    426430        }
    427431    }
Note: See TracChangeset for help on using the changeset viewer.