Ticket #22808: 22808.2.patch

File 22808.2.patch, 4.2 KB (added by taylor.smock, 20 months ago)
  • src/org/openstreetmap/josm/command/AddPrimitivesCommand.java

    Subject: [PATCH] Fix #22808: Undoing "Paste" for ways of a route relation is very slow
    ---
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java b/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java
    a b  
    1717import org.openstreetmap.josm.data.osm.NodeData;
    1818import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1919import org.openstreetmap.josm.data.osm.PrimitiveData;
     20import org.openstreetmap.josm.data.osm.PrimitiveId;
    2021import org.openstreetmap.josm.tools.CheckParameterUtil;
    2122
    2223/**
     
    127128            createdPrimitives = PurgeCommand.topoSort(createdPrimitives);
    128129        }
    129130        // reversed order, see #14620
     131        List<PrimitiveId> toRemove = new ArrayList<>(this.createdPrimitives.size());
    130132        for (int i = createdPrimitives.size() - 1; i >= 0; i--) {
    131133            OsmPrimitive osm = createdPrimitives.get(i);
    132134            Optional<PrimitiveData> previous = preExistingData.stream()
     
    134136            if (previous.isPresent()) {
    135137                osm.load(previous.get());
    136138            } else {
     139                toRemove.add(osm);
    137140                ds.removePrimitive(osm);
    138141            }
    139142        }
     143        ds.removePrimitives(toRemove);
    140144    }
    141145
    142146    @Override
  • src/org/openstreetmap/josm/data/osm/DataSet.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/src/org/openstreetmap/josm/data/osm/DataSet.java b/src/org/openstreetmap/josm/data/osm/DataSet.java
    a b  
    55
    66import java.awt.geom.Area;
    77import java.util.ArrayList;
     8import java.util.Arrays;
    89import java.util.Collection;
    910import java.util.Collections;
    1011import java.util.HashMap;
     
    564565        });
    565566    }
    566567
     568    /**
     569     * Removes primitives from the dataset. This method only removes the
     570     * primitives form the respective collection of primitives managed
     571     * by this dataset, i.e. from {@code store.nodes}, {@code store.ways}, or
     572     * {@code store.relations}. References from other primitives to this
     573     * primitive are left unchanged.
     574     *
     575     * @param primitiveIds the ids of the primitive
     576     * @throws IllegalStateException if the dataset is read-only
     577     * @since xxx
     578     */
     579    public void removePrimitives(PrimitiveId... primitiveIds) {
     580        this.removePrimitives(Arrays.asList(primitiveIds));
     581    }
     582
     583    /**
     584     * Removes primitives from the dataset. This method only removes the
     585     * primitives form the respective collection of primitives managed
     586     * by this dataset, i.e. from {@code store.nodes}, {@code store.ways}, or
     587     * {@code store.relations}. References from other primitives to this
     588     * primitive are left unchanged.
     589     *
     590     * @param primitiveIds the ids of the primitive
     591     * @throws IllegalStateException if the dataset is read-only
     592     * @since xxx
     593     */
     594    public void removePrimitives(Collection<PrimitiveId> primitiveIds) {
     595        checkModifiable();
     596        update(() -> {
     597            final List<OsmPrimitive> removed = new ArrayList<>(primitiveIds.size());
     598            for (PrimitiveId primitiveId : primitiveIds) {
     599                OsmPrimitive primitive = this.getPrimitiveByIdChecked(primitiveId);
     600                if (primitive == null) {
     601                    continue;
     602                }
     603                removePrimitiveImpl(primitive);
     604                removed.add(primitive);
     605            }
     606            firePrimitivesRemoved(removed, false);
     607        });
     608    }
     609
    567610    private void removePrimitiveImpl(OsmPrimitive primitive) {
    568611        clearSelection(primitive.getPrimitiveId());
    569612        if (primitive.isSelected()) {