Changeset 35671 in osm for applications


Ignore:
Timestamp:
2020-12-08T07:50:54+01:00 (3 years ago)
Author:
GerdP
Message:

see #19885: memory leak with "temporary" objects in validator and actions

  • simplify code, use ChangeMembersCommand instead of ChangeCommand
Location:
applications/editors/josm/plugins/utilsplugin2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/utilsplugin2/build.xml

    r35487 r35671  
    55    <property name="commit.message" value="[josm_utilsplugin2]: select boundary by double-click; multitagger table highlights"/>
    66    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    7     <property name="plugin.main.version" value="16567"/>
     7    <property name="plugin.main.version" value="17199"/>
    88
    99    <property name="plugin.author" value="Kalle Lampila, Upliner, Zverik, akks, joshdoe and others"/>
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/PasteRelationsAction.java

    r35579 r35671  
    1616
    1717import org.openstreetmap.josm.actions.JosmAction;
    18 import org.openstreetmap.josm.command.ChangeCommand;
     18import org.openstreetmap.josm.command.ChangeMembersCommand;
    1919import org.openstreetmap.josm.command.Command;
    2020import org.openstreetmap.josm.command.SequenceCommand;
     
    8282        for (Map.Entry<Relation, String> entry : relations.entrySet()) {
    8383            Relation rel = entry.getKey();
    84             Relation r = new Relation(rel);
     84            List<RelationMember> members = new ArrayList<>(rel.getMembers());
    8585            boolean changed = false;
    8686            for (OsmPrimitive p : selection) {
    87                 if (!r.getMemberPrimitives().contains(p) && !r.equals(p)) {
     87                if (!rel.getMemberPrimitives().contains(p) && !rel.equals(p)) {
    8888                    String role = entry.getValue();
    89                     if ("associatedStreet".equals(r.get("type"))) {
    90                         if (p.get("highway") != null) {
     89                    if (rel.hasTag("type", "associatedStreet")) {
     90                        if (p.hasKey("highway")) {
    9191                            role = "street";
    92                         } else if (p.get("addr:housenumber") != null) {
     92                        } else if (p.hasKey("addr:housenumber")) {
    9393                            role = "house";
    9494                        }
    9595                    }
    96                     r.addMember(new RelationMember(role, p));
     96                    members.add(new RelationMember(role, p));
    9797                    changed = true;
    9898                }
    9999            }
    100             if (changed)
    101                 commands.add(new ChangeCommand(rel, r));
     100            if (changed) {
     101                commands.add(new ChangeMembersCommand(rel, members));
     102            }
    102103        }
    103104
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/UnGlueRelationAction.java

    r35580 r35671  
    8585        } else {
    8686            UndoRedoHandler.getInstance().add(new SequenceCommand(tr("Unglued Relations"), cmds));
    87             //Set selection all primiteves (new and old)
     87            //Set selection all primitives (new and old)
    8888            newPrimitives.addAll(selection);
    8989            ds.setSelected(newPrimitives);
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceMembershipAction.java

    r34454 r35671  
    1616
    1717import org.openstreetmap.josm.actions.JosmAction;
    18 import org.openstreetmap.josm.command.ChangeCommand;
     18import org.openstreetmap.josm.command.ChangeMembersCommand;
    1919import org.openstreetmap.josm.command.Command;
    2020import org.openstreetmap.josm.data.UndoRedoHandler;
     
    7171        for (final Map.Entry<Relation, Set<RelationToChildReference>> i : byRelation.entrySet()) {
    7272            final Relation oldRelation = i.getKey();
    73             final Relation newRelation = new Relation(oldRelation);
     73            List<RelationMember> members = new ArrayList<>(oldRelation.getMembers());
     74            boolean modified = false;
    7475            for (final RelationToChildReference reference : i.getValue()) {
    75                 newRelation.setMember(reference.getPosition(), new RelationMember(reference.getRole(), secondObject));
     76                members.set(reference.getPosition(), new RelationMember(reference.getRole(), secondObject));
     77                modified = true;
    7678            }
    77             commands.add(new ChangeCommand(oldRelation, newRelation));
     79            if (modified) {
     80                commands.add(new ChangeMembersCommand(oldRelation, members));
     81            }
    7882        }
    7983
Note: See TracChangeset for help on using the changeset viewer.