Ignore:
Timestamp:
21.12.2011 12:58:59 (5 months ago)
Author:
Don-vip
Message:

see #7159 - Layer merging performance

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
3 edited

Legend:

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

    r4682 r4684  
    648648     */ 
    649649    public boolean hasSameTags(OsmPrimitive other) { 
    650         return getKeys().equals(other.getKeys()); 
     650        // We cannot directly use Arrays.equals(keys, other.keys) as keys is not ordered by key 
     651        // but we can at least check if both arrays are null or of the same size before creating  
     652        // and comparing the key maps (costly operation, see #7159) 
     653        return (keys == null && other.keys == null)  
     654            || (keys != null && other.keys != null && keys.length == other.keys.length && (keys.length == 0 || getKeys().equals(other.getKeys()))); 
    651655    } 
    652656 
  • trunk/src/org/openstreetmap/josm/data/osm/DataSetMerger.java

    r4253 r4684  
    1616import org.openstreetmap.josm.data.conflict.Conflict; 
    1717import org.openstreetmap.josm.data.conflict.ConflictCollection; 
     18import org.openstreetmap.josm.gui.progress.ProgressMonitor; 
    1819import org.openstreetmap.josm.tools.CheckParameterUtil; 
    1920 
     
    7778     * @param source  the other primitive 
    7879     */ 
    79     protected void mergePrimitive(OsmPrimitive source) { 
     80    protected void mergePrimitive(OsmPrimitive source, Collection<? extends OsmPrimitive> candidates) { 
    8081        if (!source.isNew() ) { 
    8182            // try to merge onto a matching primitive with the same 
     
    9495            // yet but which is equal in its semantic attributes 
    9596            // 
    96             Collection<? extends OsmPrimitive> candidates = null; 
    97             switch (source.getType()) { 
    98             case NODE: candidates = targetDataSet.getNodes(); break; 
    99             case WAY: candidates  = targetDataSet.getWays(); break; 
    100             case RELATION: candidates = targetDataSet.getRelations(); break; 
    101             default: throw new AssertionError(); 
    102             } 
    10397            for (OsmPrimitive target : candidates) { 
    10498                if (!target.isNew() || target.isDeleted()) { 
     
    382376     */ 
    383377    public void merge() { 
     378        merge(null); 
     379    } 
     380 
     381    /** 
     382     * Runs the merge operation. Successfully merged {@see OsmPrimitive}s are in 
     383     * {@see #getMyDataSet()}. 
     384     * 
     385     * See {@see #getConflicts()} for a map of conflicts after the merge operation. 
     386     */ 
     387    public void merge(ProgressMonitor progressMonitor) { 
    384388        if (sourceDataSet == null) 
    385389            return; 
     390        if (progressMonitor != null) { 
     391            progressMonitor.beginTask(tr("Merging data..."), sourceDataSet.allPrimitives().size()); 
     392        } 
    386393        targetDataSet.beginUpdate(); 
    387394        try { 
     395                ArrayList<? extends OsmPrimitive> candidates = new ArrayList<Node>(targetDataSet.getNodes()); 
    388396            for (Node node: sourceDataSet.getNodes()) { 
    389                 mergePrimitive(node); 
    390             } 
     397                mergePrimitive(node, candidates); 
     398                if (progressMonitor != null) { 
     399                    progressMonitor.worked(1); 
     400                } 
     401            } 
     402            candidates.clear(); 
     403            candidates = new ArrayList<Way>(targetDataSet.getWays()); 
    391404            for (Way way: sourceDataSet.getWays()) { 
    392                 mergePrimitive(way); 
    393             } 
     405                mergePrimitive(way, candidates); 
     406                if (progressMonitor != null) { 
     407                    progressMonitor.worked(1); 
     408                } 
     409            } 
     410            candidates.clear(); 
     411            candidates = new ArrayList<Relation>(targetDataSet.getRelations()); 
    394412            for (Relation relation: sourceDataSet.getRelations()) { 
    395                 mergePrimitive(relation); 
    396             } 
     413                mergePrimitive(relation, candidates); 
     414                if (progressMonitor != null) { 
     415                    progressMonitor.worked(1); 
     416                } 
     417            } 
     418            candidates.clear(); 
    397419            fixReferences(); 
    398420        } finally { 
    399421            targetDataSet.endUpdate(); 
    400422        } 
     423        if (progressMonitor != null) { 
     424            progressMonitor.finishTask(); 
     425        } 
    401426    } 
    402427 
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r4612 r4684  
    966966        if (!isNew() &&  id != other.id) 
    967967            return false; 
    968         if (isIncomplete() && ! other.isIncomplete() || !isIncomplete()  && other.isIncomplete()) 
     968//        if (isIncomplete() && ! other.isIncomplete() || !isIncomplete()  && other.isIncomplete()) 
     969        if (isIncomplete() ^ other.isIncomplete()) // exclusive or operator for performance (see #7159) 
    969970            return false; 
    970971        // can't do an equals check on the internal keys array because it is not ordered 
Note: See TracChangeset for help on using the changeset viewer.