Ignore:
Timestamp:
2017-02-26T00:59:32+01:00 (7 years ago)
Author:
Don-vip
Message:

fix #3346 - improve drastically the performance of fixing duplicate nodes by:

  • caching data sources area computation
  • moving layer invalidation from UndoRedoHandler.addNoRedraw to UndoRedoHandler.add
  • avoiding any EDT call when building tag conflict dialog if it's not meant to be displayed
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateWay.java

    r11129 r11627  
    249249    public Command fixError(TestError testError) {
    250250        Collection<? extends OsmPrimitive> sel = testError.getPrimitives();
    251         Set<Way> ways = new HashSet<>();
     251        Set<Way> wayz = new HashSet<>();
    252252
    253253        for (OsmPrimitive osm : sel) {
    254254            if (osm instanceof Way && !osm.isDeleted()) {
    255                 ways.add((Way) osm);
    256             }
    257         }
    258 
    259         if (ways.size() < 2)
     255                wayz.add((Way) osm);
     256            }
     257        }
     258
     259        if (wayz.size() < 2)
    260260            return null;
    261261
    262262        long idToKeep = 0;
    263         Way wayToKeep = ways.iterator().next();
     263        Way wayToKeep = wayz.iterator().next();
    264264        // Find the way that is member of one or more relations. (If any)
    265265        Way wayWithRelations = null;
    266266        List<Relation> relations = null;
    267         for (Way w : ways) {
     267        for (Way w : wayz) {
    268268            List<Relation> rel = OsmPrimitive.getFilteredList(w.getReferrers(), Relation.class);
    269269            if (!rel.isEmpty()) {
     
    284284
    285285        // Fix relations.
    286         if (wayWithRelations != null && wayToKeep != wayWithRelations) {
     286        if (wayWithRelations != null && relations != null && wayToKeep != wayWithRelations) {
    287287            for (Relation rel : relations) {
    288288                Relation newRel = new Relation(rel);
     
    297297        }
    298298
    299         //Delete all ways in the list
    300         //Note: nodes are not deleted, these can be detected and deleted at next pass
    301         ways.remove(wayToKeep);
    302         commands.add(new DeleteCommand(ways));
     299        // Delete all ways in the list
     300        // Note: nodes are not deleted, these can be detected and deleted at next pass
     301        wayz.remove(wayToKeep);
     302        commands.add(new DeleteCommand(wayz));
    303303        return new SequenceCommand(tr("Delete duplicate ways"), commands);
    304304    }
     
    309309            return false;
    310310
    311         //Do not automatically fix same ways with different tags
     311        // Do not automatically fix same ways with different tags
    312312        if (testError.getCode() != DUPLICATE_WAY) return false;
    313313
    314314        // We fix it only if there is no more than one way that is relation member.
    315315        Collection<? extends OsmPrimitive> sel = testError.getPrimitives();
    316         Set<Way> ways = new HashSet<>();
     316        Set<Way> wayz = new HashSet<>();
    317317
    318318        for (OsmPrimitive osm : sel) {
    319319            if (osm instanceof Way) {
    320                 ways.add((Way) osm);
    321             }
    322         }
    323 
    324         if (ways.size() < 2)
     320                wayz.add((Way) osm);
     321            }
     322        }
     323
     324        if (wayz.size() < 2)
    325325            return false;
    326326
    327327        int waysWithRelations = 0;
    328         for (Way w : ways) {
     328        for (Way w : wayz) {
    329329            List<Relation> rel = OsmPrimitive.getFilteredList(w.getReferrers(), Relation.class);
    330330            if (!rel.isEmpty()) {
Note: See TracChangeset for help on using the changeset viewer.