Changeset 18606 in josm for trunk/src/org


Ignore:
Timestamp:
2022-11-29T08:29:55+01:00 (2 years ago)
Author:
GerdP
Message:

fix #22529: possibly improve performance in class ChangesetDataSet

  • avoid repeated calls of getPrimitiveId() which creates instances of SimplePrimitiveId
  • use map.computeIfAbsent() as recommended by sonarlint
File:
1 edited

Legend:

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

    r16553 r18606  
    6262     * @throws IllegalArgumentException if the same primitive was already stored with a higher or equal version
    6363     */
    64     public void put(HistoryOsmPrimitive primitive, ChangesetModificationType cmt) {
     64    public void put(final HistoryOsmPrimitive primitive, ChangesetModificationType cmt) {
    6565        CheckParameterUtil.ensureParameterNotNull(primitive, "primitive");
    6666        CheckParameterUtil.ensureParameterNotNull(cmt, "cmt");
    6767        DefaultChangesetDataSetEntry csEntry = new DefaultChangesetDataSetEntry(cmt, primitive);
    68         Object val = entryMap.get(primitive.getPrimitiveId());
     68        final PrimitiveId pid = primitive.getPrimitiveId();
    6969        ChangesetDataSetEntry[] entries;
    70         if (val == null) {
    71             entryMap.put(primitive.getPrimitiveId(), csEntry);
     70        Object val = entryMap.computeIfAbsent(pid, k -> csEntry);
     71        if (val == csEntry)
    7272            return;
    73         }
    7473        if (val instanceof ChangesetDataSetEntry) {
    7574            entries = new ChangesetDataSetEntry[2];
     
    7877                throw new IllegalArgumentException(
    7978                        tr("Changeset {0}: Unexpected order of versions for {1}: v{2} is not higher than v{3}",
    80                                 String.valueOf(primitive.getChangesetId()), primitive.getPrimitiveId(),
     79                                String.valueOf(primitive.getChangesetId()), pid,
    8180                                primitive.getVersion(), entries[0].getPrimitive().getVersion()));
    8281            }
     
    8685        if (entries[1] != null) {
    8786            Logging.info("Changeset {0}: Change of {1} v{2} is replaced by version v{3}",
    88                     String.valueOf(primitive.getChangesetId()), primitive.getPrimitiveId(),
     87                    String.valueOf(primitive.getChangesetId()), pid,
    8988                    entries[1].getPrimitive().getVersion(), primitive.getVersion());
    9089        }
    9190        entries[1] = csEntry;
    92         entryMap.put(primitive.getPrimitiveId(), entries);
     91        entryMap.put(pid, entries);
    9392    }
    9493
Note: See TracChangeset for help on using the changeset viewer.