Changeset 17136 in josm for trunk/src


Ignore:
Timestamp:
2020-10-09T14:19:58+02:00 (4 years ago)
Author:
GerdP
Message:

see #19898: Performance improvements for DatasetMerger
Avoid to avoid to materialise unneeded copies of SubclassFilteredCollection

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

Legend:

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

    r16187 r17136  
    425425        }
    426426        targetDataSet.update(() -> {
    427             List<? extends OsmPrimitive> candidates = new ArrayList<>(targetDataSet.getNodes());
     427            List<? extends OsmPrimitive> candidates = null;
    428428            for (Node node: sourceDataSet.getNodes()) {
     429                // lazy initialisation to improve performance, see #19898
     430                if (candidates == null) {
     431                    candidates = new ArrayList<>(targetDataSet.getNodes());
     432                }
    429433                mergePrimitive(node, candidates);
    430434                if (progressMonitor != null) {
     
    432436                }
    433437            }
    434             candidates.clear();
    435             candidates = new ArrayList<>(targetDataSet.getWays());
     438            candidates = null;
    436439            for (Way way: sourceDataSet.getWays()) {
     440                // lazy initialisation to improve performance
     441                if (candidates == null) {
     442                    candidates = new ArrayList<>(targetDataSet.getWays());
     443                }
    437444                mergePrimitive(way, candidates);
    438445                if (progressMonitor != null) {
     
    440447                }
    441448            }
    442             candidates.clear();
    443             candidates = new ArrayList<>(targetDataSet.getRelations());
     449            candidates = null;
    444450            for (Relation relation: sourceDataSet.getRelations()) {
     451                // lazy initialisation to improve performance
     452                if (candidates == null) {
     453                    candidates = new ArrayList<>(targetDataSet.getRelations());
     454                }
    445455                mergePrimitive(relation, candidates);
    446456                if (progressMonitor != null) {
     
    448458                }
    449459            }
    450             candidates.clear();
     460            candidates = null;
    451461            fixReferences();
    452462
  • trunk/src/org/openstreetmap/josm/io/OsmServerBackreferenceReader.java

    r16913 r17136  
    215215        progressMonitor.beginTask(null, 2);
    216216        try {
    217             Collection<Way> waysToCheck = new ArrayList<>(ds.getWays());
    218217            if (isReadFull() || (primitiveType == OsmPrimitiveType.NODE && !isAllowIncompleteParentWays())) {
     218                Collection<Way> waysToCheck = new ArrayList<>(ds.getWays());
    219219                for (Way way: waysToCheck) {
    220220                    if (!way.isNew() && way.hasIncompleteNodes()) {
Note: See TracChangeset for help on using the changeset viewer.