Index: /trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java	(revision 2564)
+++ /trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java	(revision 2565)
@@ -2,6 +2,6 @@
 package org.openstreetmap.josm.actions;
 
+import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
 import static org.openstreetmap.josm.tools.I18n.tr;
-import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
 
 import java.awt.event.ActionEvent;
@@ -24,5 +24,4 @@
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;
 import org.openstreetmap.josm.tools.Shortcut;
 
@@ -173,8 +172,6 @@
             if (a1 < 999) {
                 // if it is, delete it
-                CollectBackReferencesVisitor refs = new CollectBackReferencesVisitor(getCurrentDataSet());
-                refs.initialize();
-                refs.visit(n1);
-                if (refs.getData().isEmpty() || ((refs.getData().size() == 1) && (refs.getData().contains(existingWay)))) {
+                List<OsmPrimitive> parents = n1.getReferrers();
+                if (parents.isEmpty() || ((parents.size() == 1) && (parents.contains(existingWay)))) {
                     cmds.add(new DeleteCommand(n1));
                 }
Index: /trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java	(revision 2564)
+++ /trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java	(revision 2565)
@@ -25,10 +25,9 @@
 import org.openstreetmap.josm.command.DeleteCommand;
 import org.openstreetmap.josm.command.SequenceCommand;
-import org.openstreetmap.josm.data.osm.BackreferencedDataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.RelationToChildReference;
 import org.openstreetmap.josm.data.osm.TagCollection;
 import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.data.osm.BackreferencedDataSet.RelationToChildReference;
 import org.openstreetmap.josm.gui.DefaultNameFormatter;
 import org.openstreetmap.josm.gui.HelpAwareOptionPane;
@@ -90,28 +89,4 @@
 
     /**
-     * Merges the nodes in <code>node</code> onto one of the nodes. Uses the dataset
-     * managed by <code>layer</code> as reference.
-     *
-     * @param layer the reference data layer. Must not be null.
-     * @param nodes the collection of nodes. Ignored if null.
-     * @param targetNode the target node the collection of nodes is merged to. Must not be null.
-     * @throws IllegalArgumentException thrown if layer is null
-     * @throws IllegalArgumentException thrown if targetNode is null
-     *
-     */
-    public static Command mergeNodes(OsmDataLayer layer, Collection<Node> nodes, Node targetNode) throws IllegalArgumentException{
-        if (layer == null)
-            throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "nodes"));
-        if (targetNode == null)
-            throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "targetNode"));
-
-        if (nodes == null)
-            return null;
-        nodes.remove(null); // just in case
-        BackreferencedDataSet backreferences = new BackreferencedDataSet();
-        return mergeNodes(layer,backreferences, nodes, targetNode);
-    }
-
-    /**
      * Fixes the parent ways referring to one of the nodes.
      *
@@ -119,14 +94,13 @@
      * which is referred to by a relation.
      *
-     * @param backreferences the backreference data set
      * @param nodesToDelete the collection of nodes to be deleted
      * @param targetNode the target node the other nodes are merged to
      * @return a list of commands; null, if the ways could not be fixed
      */
-    protected static List<Command> fixParentWays(BackreferencedDataSet backreferences, Collection<OsmPrimitive> nodesToDelete, Node targetNode) {
+    protected static List<Command> fixParentWays(Collection<OsmPrimitive> nodesToDelete, Node targetNode) {
         List<Command> cmds = new ArrayList<Command>();
         Set<Way> waysToDelete = new HashSet<Way>();
 
-        for (Way w: OsmPrimitive.getFilteredList(backreferences.getParents(nodesToDelete), Way.class)) {
+        for (Way w: OsmPrimitive.getFilteredList(OsmPrimitive.getReferrer(nodesToDelete), Way.class)) {
             ArrayList<Node> newNodes = new ArrayList<Node>(w.getNodesCount());
             for (Node n: w.getNodes()) {
@@ -145,5 +119,5 @@
             }
             if (newNodes.size() < 2) {
-                if (backreferences.getParents(w).isEmpty()) {
+                if (w.getReferrers().isEmpty()) {
                     waysToDelete.add(w);
                 } else {
@@ -171,5 +145,5 @@
                     return null;
                 }
-            } else if(newNodes.size() < 2 && backreferences.getParents(w).isEmpty()) {
+            } else if(newNodes.size() < 2 && w.getReferrers().isEmpty()) {
                 waysToDelete.add(w);
             } else {
@@ -187,16 +161,12 @@
     /**
      * Merges the nodes in <code>nodes</code> onto one of the nodes. Uses the dataset
-     * managed by <code>layer</code> as reference. <code>backreferences</code> is a precomputed
-     * collection of all parent/child references in the dataset.
+     * managed by <code>layer</code> as reference.
      *
      * @param layer layer the reference data layer. Must not be null.
-     * @param backreferences if null, backreferences are first computed from layer.data; otherwise
-     *    backreferences.getSource() == layer.data must be true
      * @param nodes the collection of nodes. Ignored if null.
      * @param targetNode the target node the collection of nodes is merged to. Must not be null.
      * @throw IllegalArgumentException thrown if layer is null
-     * @throw IllegalArgumentException thrown if  backreferences.getSource() != layer.data
      */
-    public static Command mergeNodes(OsmDataLayer layer, BackreferencedDataSet backreferences, Collection<Node> nodes, Node targetNode) {
+    public static Command mergeNodes(OsmDataLayer layer,Collection<Node> nodes, Node targetNode) {
         if (layer == null)
             throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "nodes"));
@@ -205,9 +175,7 @@
         if (nodes == null)
             return null;
-        if (backreferences == null) {
-            backreferences = new BackreferencedDataSet();
-        }
-
-        Set<RelationToChildReference> relationToNodeReferences = backreferences.getRelationToChildReferences(nodes);
+
+
+        Set<RelationToChildReference> relationToNodeReferences = RelationToChildReference.getRelationToChildReferences(nodes);
 
         // build the tag collection
@@ -245,5 +213,4 @@
         Collection<Way> waysToDelete= new HashSet<Way>();
         List<Command> wayFixCommands = fixParentWays(
-                backreferences,
                 nodesToDelete,
                 targetNode
Index: /trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java	(revision 2564)
+++ /trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java	(revision 2565)
@@ -20,5 +20,4 @@
 import org.openstreetmap.josm.data.osm.User;
 import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;
 import org.openstreetmap.josm.tools.DateUtils;
 
@@ -33,5 +32,4 @@
     private static String  rxErrorMsg = marktr("The regex \"{0}\" had a parse error at offset {1}, full error:\n\n{2}");
     private PushbackTokenizer tokenizer;
-    private CollectBackReferencesVisitor childBackRefs;
 
     public SearchCompiler(boolean caseSensitive, boolean regexSearch, PushbackTokenizer tokenizer) {
@@ -39,5 +37,4 @@
         this.regexSearch = regexSearch;
         this.tokenizer = tokenizer;
-        childBackRefs = new CollectBackReferencesVisitor(true);
     }
 
@@ -527,7 +524,6 @@
     private static class Child extends Match {
         private final Match parent;
-        private final CollectBackReferencesVisitor childBackRefs;
-
-        public Child(Match m, CollectBackReferencesVisitor childBackRefs) {
+
+        public Child(Match m) {
             // "child" (null) should mean the same as "child()"
             // (Always). I.e. match everything
@@ -537,12 +533,9 @@
                 parent = m;
             }
-            this.childBackRefs = childBackRefs;
         }
 
         @Override public boolean match(OsmPrimitive osm) {
             boolean isChild = false;
-            childBackRefs.initialize();
-            osm.visit(childBackRefs);
-            for (OsmPrimitive p : childBackRefs.getData()) {
+            for (OsmPrimitive p : osm.getReferrers()) {
                 isChild |= parent.match(p);
             }
@@ -651,5 +644,5 @@
             return new Selected();
         else if (tok.equals("child"))
-            return new Child(parseParens(), childBackRefs);
+            return new Child(parseParens());
         else if (tok.equals("parent"))
             return new Parent(parseParens());
Index: /trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/DeleteCommand.java	(revision 2564)
+++ /trunk/src/org/openstreetmap/josm/command/DeleteCommand.java	(revision 2565)
@@ -24,13 +24,11 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.SplitWayAction;
-import org.openstreetmap.josm.data.osm.BackreferencedDataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
 import org.openstreetmap.josm.data.osm.Relation;
+import org.openstreetmap.josm.data.osm.RelationToChildReference;
 import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.data.osm.WaySegment;
-import org.openstreetmap.josm.data.osm.BackreferencedDataSet.RelationToChildReference;
-import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;
 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
 import org.openstreetmap.josm.gui.DefaultNameFormatter;
@@ -218,15 +216,12 @@
             throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", "layer"));
         if (selection == null || selection.isEmpty()) return null;
-        CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(layer.data);
-        v.initialize();
-        for (OsmPrimitive osm : selection) {
-            osm.visit(v);
-        }
-        v.getData().addAll(selection);
-        if (v.getData().isEmpty())
+        Set<OsmPrimitive> parents = OsmPrimitive.getReferrer(selection);
+        parents.addAll(selection);
+
+        if (parents.isEmpty())
             return null;
-        if (!checkAndConfirmOutlyingDeletes(layer,v.getData()) && !silent)
+        if (!checkAndConfirmOutlyingDeletes(layer,parents) && !silent)
             return null;
-        return new DeleteCommand(layer,v.getData());
+        return new DeleteCommand(layer,parents);
     }
 
@@ -246,5 +241,4 @@
      *    <li>it is not referred to by other non-deleted primitives outside of  <code>primitivesToDelete</code></li>
      * <ul>
-     * @param backreferences backreference data structure
      * @param layer  the layer in whose context primitives are deleted
      * @param primitivesToDelete  the primitives to delete
@@ -252,5 +246,5 @@
      * can be deleted too
      */
-    protected static Collection<Node> computeNodesToDelete(BackreferencedDataSet backreferences, OsmDataLayer layer, Collection<OsmPrimitive> primitivesToDelete) {
+    protected static Collection<Node> computeNodesToDelete(OsmDataLayer layer, Collection<OsmPrimitive> primitivesToDelete) {
         Collection<Node> nodesToDelete = new HashSet<Node>();
         for (Way way : OsmPrimitive.getFilteredList(primitivesToDelete, Way.class)) {
@@ -259,5 +253,5 @@
                     continue;
                 }
-                Collection<OsmPrimitive> referringPrimitives = backreferences.getParents(n);
+                Collection<OsmPrimitive> referringPrimitives = n.getReferrers();
                 referringPrimitives.removeAll(primitivesToDelete);
                 int count = 0;
@@ -314,5 +308,4 @@
             return null;
 
-        BackreferencedDataSet backreferences = new BackreferencedDataSet();
         Set<OsmPrimitive> primitivesToDelete = new HashSet<OsmPrimitive>(selection);
         Collection<Way> waysToBeChanged = new HashSet<Way>();
@@ -321,5 +314,5 @@
             // delete untagged nodes only referenced by primitives in primitivesToDelete,
             // too
-            Collection<Node> nodesToDelete = computeNodesToDelete(backreferences, layer, primitivesToDelete);
+            Collection<Node> nodesToDelete = computeNodesToDelete(layer, primitivesToDelete);
             primitivesToDelete.addAll(nodesToDelete);
         }
@@ -328,5 +321,5 @@
             return null;
 
-        waysToBeChanged.addAll(OsmPrimitive.getFilteredSet(backreferences.getParents(primitivesToDelete), Way.class));
+        waysToBeChanged.addAll(OsmPrimitive.getFilteredSet(OsmPrimitive.getReferrer(primitivesToDelete), Way.class));
 
         Collection<Command> cmds = new LinkedList<Command>();
@@ -345,5 +338,5 @@
         //
         if (!silent) {
-            Set<RelationToChildReference> references = backreferences.getRelationToChildReferences(primitivesToDelete);
+            Set<RelationToChildReference> references = RelationToChildReference.getRelationToChildReferences(primitivesToDelete);
             Iterator<RelationToChildReference> it = references.iterator();
             while(it.hasNext()) {
@@ -364,5 +357,5 @@
         // remove the objects from their parent relations
         //
-        Iterator<Relation> iterator = OsmPrimitive.getFilteredSet(backreferences.getParents(primitivesToDelete), Relation.class).iterator();
+        Iterator<Relation> iterator = OsmPrimitive.getFilteredSet(OsmPrimitive.getReferrer(primitivesToDelete), Relation.class).iterator();
         while (iterator.hasNext()) {
             Relation cur = iterator.next();
Index: /trunk/src/org/openstreetmap/josm/command/PurgePrimitivesCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/PurgePrimitivesCommand.java	(revision 2564)
+++ /trunk/src/org/openstreetmap/josm/command/PurgePrimitivesCommand.java	(revision 2565)
@@ -17,5 +17,4 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.conflict.ConflictCollection;
-import org.openstreetmap.josm.data.osm.BackreferencedDataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -51,9 +50,4 @@
     private Set<OsmPrimitive> origVersionsOfTouchedPrimitives;
 
-    /**
-     * the data structure with child->parent references
-     */
-    private BackreferencedDataSet backreferenceDataSet;
-
     protected void init(Collection<OsmPrimitive> toPurge) {
         this.toPurge = toPurge;
@@ -141,5 +135,5 @@
     protected void removeReferecesToPrimitive(OsmPrimitive child, Set<OsmPrimitive> hive) {
         hive.remove(child);
-        for (OsmPrimitive parent: this.backreferenceDataSet.getParents(child)) {
+        for (OsmPrimitive parent: child.getReferrers()) {
             if (toPurge.contains(parent))
                 // parent itself is to be purged. This method is going to be
@@ -177,7 +171,4 @@
     @Override
     public boolean executeCommand() {
-        if (backreferenceDataSet == null) {
-            backreferenceDataSet = new BackreferencedDataSet();
-        }
         HashSet<OsmPrimitive> hive = new HashSet<OsmPrimitive>();
 
@@ -198,6 +189,4 @@
             }
         }
-        // we don't need this any more
-        backreferenceDataSet = null;
         return super.executeCommand();
     }
@@ -231,13 +220,3 @@
         super.undoCommand();
     }
-
-    /**
-     * Use to inject a backreference data set used when the command
-     * is executed.
-     *
-     * @param ds the backreference data set
-     */
-    public void setBackreferenceDataSet(BackreferencedDataSet ds) {
-        this.backreferenceDataSet = ds;
-    }
 }
Index: unk/src/org/openstreetmap/josm/data/osm/BackreferencedDataSet.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/BackreferencedDataSet.java	(revision 2564)
+++ 	(revision )
@@ -1,152 +1,0 @@
-// License: GPL. For details, see LICENSE file.
-package org.openstreetmap.josm.data.osm;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-public class BackreferencedDataSet {
-    public static class RelationToChildReference {
-        private Relation parent;
-        private int position;
-        private String role;
-        private OsmPrimitive child;
-
-        public RelationToChildReference(Relation parent, int position, String role, OsmPrimitive child) {
-            this.parent = parent;
-            this.position = position;
-            this.role = role;
-            this.child = child;
-        }
-
-        public RelationToChildReference(Relation parent, int position, RelationMember member) {
-            this.parent = parent;
-            this.position = position;
-            this.role = member.getRole();
-            this.child = member.getMember();
-        }
-
-        public Relation getParent() {
-            return parent;
-        }
-
-        public int getPosition() {
-            return position;
-        }
-
-        public String getRole() {
-            return role;
-        }
-
-        public OsmPrimitive getChild() {
-            return child;
-        }
-
-        @Override
-        public int hashCode() {
-            final int prime = 31;
-            int result = 1;
-            result = prime * result + ((child == null) ? 0 : child.hashCode());
-            result = prime * result + ((parent == null) ? 0 : parent.hashCode());
-            result = prime * result + position;
-            result = prime * result + ((role == null) ? 0 : role.hashCode());
-            return result;
-        }
-        @Override
-        public boolean equals(Object obj) {
-            if (this == obj)
-                return true;
-            if (obj == null)
-                return false;
-            if (getClass() != obj.getClass())
-                return false;
-            RelationToChildReference other = (RelationToChildReference) obj;
-            if (child == null) {
-                if (other.child != null)
-                    return false;
-            } else if (!child.equals(other.child))
-                return false;
-            if (parent == null) {
-                if (other.parent != null)
-                    return false;
-            } else if (!parent.equals(other.parent))
-                return false;
-            if (position != other.position)
-                return false;
-            if (role == null) {
-                if (other.role != null)
-                    return false;
-            } else if (!role.equals(other.role))
-                return false;
-            return true;
-        }
-    }
-
-    /**
-     * Replies the set of parent primitives for a given child primitive. Replies
-     * an empty set if no parents refer to the child.
-     *
-     * @param child the child primitive
-     * @return  the set of parent primitives for a given child primitive.
-     */
-    public Set<OsmPrimitive> getParents(OsmPrimitive child) {
-        return new HashSet<OsmPrimitive>(child.getReferrers());
-    }
-
-    public Set<OsmPrimitive> getParents(Collection<? extends OsmPrimitive> children) {
-        if (children == null) return Collections.emptySet();
-        children.remove(null);
-
-        Set<OsmPrimitive> parents = new HashSet<OsmPrimitive>();
-        for(OsmPrimitive child: children) {
-            parents.addAll(child.getReferrers());
-        }
-        return parents;
-    }
-
-    /**
-     * Replies true if there is at least one parent referring to child;
-     * false otherwise
-     *
-     * @param child the child primitive
-     * @return true if there is at least one parent referring to child;
-     */
-    public boolean hasParents(OsmPrimitive child) {
-        return ! getParents(child).isEmpty();
-    }
-
-    /**
-     * Replies a set of all {@see RelationToChildReference}s for a given child primitive.
-     *
-     * @param child the child primitive
-     * @return  a set of all {@see RelationToChildReference}s for a given child primitive
-     */
-    public Set<RelationToChildReference> getRelationToChildReferences(OsmPrimitive child) {
-        Set<Relation> parents = OsmPrimitive.getFilteredSet(getParents(child), Relation.class);
-        Set<RelationToChildReference> references = new HashSet<RelationToChildReference>();
-        for (Relation parent: parents) {
-            for (int i=0; i < parent.getMembersCount(); i++) {
-                if (parent.getMember(i).refersTo(child)) {
-                    references.add(new RelationToChildReference(parent, i, parent.getMember(i)));
-                }
-            }
-        }
-        return references;
-    }
-
-    /**
-     * Replies a set of all {@see RelationToChildReference}s for a collection of child primitives
-     *
-     * @param children the collection of child primitives
-     * @return  a set of all {@see RelationToChildReference}s to the children in the collection of child
-     * primitives
-     */
-    public Set<RelationToChildReference> getRelationToChildReferences(Collection<? extends OsmPrimitive> children) {
-        Set<RelationToChildReference> references = new HashSet<RelationToChildReference>();
-        for (OsmPrimitive child: children) {
-            references.addAll(getRelationToChildReferences(child));
-        }
-        return references;
-    }
-}
Index: /trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java	(revision 2564)
+++ /trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java	(revision 2565)
@@ -149,4 +149,21 @@
     }
 
+    /**
+     * Replies the collection of referring primitives for the primitives in <code>primitives</code>.
+     * 
+     * @param primitives the collection of primitives.
+     * @return the collection of referring primitives for the primitives in <code>primitives</code>;
+     * empty set if primitives is null or if there are no referring primitives
+     */
+    static public Set<OsmPrimitive> getReferrer(Collection<? extends OsmPrimitive> primitives) {
+        HashSet<OsmPrimitive> ret = new HashSet<OsmPrimitive>();
+        if (primitives == null || primitives.isEmpty()) return ret;
+        for (OsmPrimitive p: primitives) {
+            ret.addAll(p.getReferrers());
+        }
+        return ret;
+    }
+
+
     /* mappaint data */
     public ElemStyle mappaintStyle = null;
Index: /trunk/src/org/openstreetmap/josm/data/osm/RelationToChildReference.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/RelationToChildReference.java	(revision 2565)
+++ /trunk/src/org/openstreetmap/josm/data/osm/RelationToChildReference.java	(revision 2565)
@@ -0,0 +1,117 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.data.osm;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+public class RelationToChildReference {
+
+    /**
+     * Replies a set of all {@see RelationToChildReference}s for a given child primitive.
+     *
+     * @param child the child primitive
+     * @return  a set of all {@see RelationToChildReference}s for a given child primitive
+     */
+    static public Set<RelationToChildReference> getRelationToChildReferences(OsmPrimitive child) {
+        Set<Relation> parents = OsmPrimitive.getFilteredSet(child.getReferrers(), Relation.class);
+        Set<RelationToChildReference> references = new HashSet<RelationToChildReference>();
+        for (Relation parent: parents) {
+            for (int i=0; i < parent.getMembersCount(); i++) {
+                if (parent.getMember(i).refersTo(child)) {
+                    references.add(new RelationToChildReference(parent, i, parent.getMember(i)));
+                }
+            }
+        }
+        return references;
+    }
+
+    /**
+     * Replies a set of all {@see RelationToChildReference}s for a collection of child primitives
+     *
+     * @param children the collection of child primitives
+     * @return  a set of all {@see RelationToChildReference}s to the children in the collection of child
+     * primitives
+     */
+    static public Set<RelationToChildReference> getRelationToChildReferences(Collection<? extends OsmPrimitive> children) {
+        Set<RelationToChildReference> references = new HashSet<RelationToChildReference>();
+        for (OsmPrimitive child: children) {
+            references.addAll(getRelationToChildReferences(child));
+        }
+        return references;
+    }
+
+    private Relation parent;
+    private int position;
+    private String role;
+    private OsmPrimitive child;
+
+    public RelationToChildReference(Relation parent, int position, String role, OsmPrimitive child) {
+        this.parent = parent;
+        this.position = position;
+        this.role = role;
+        this.child = child;
+    }
+
+    public RelationToChildReference(Relation parent, int position, RelationMember member) {
+        this.parent = parent;
+        this.position = position;
+        this.role = member.getRole();
+        this.child = member.getMember();
+    }
+
+    public Relation getParent() {
+        return parent;
+    }
+
+    public int getPosition() {
+        return position;
+    }
+
+    public String getRole() {
+        return role;
+    }
+
+    public OsmPrimitive getChild() {
+        return child;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((child == null) ? 0 : child.hashCode());
+        result = prime * result + ((parent == null) ? 0 : parent.hashCode());
+        result = prime * result + position;
+        result = prime * result + ((role == null) ? 0 : role.hashCode());
+        return result;
+    }
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        RelationToChildReference other = (RelationToChildReference) obj;
+        if (child == null) {
+            if (other.child != null)
+                return false;
+        } else if (!child.equals(other.child))
+            return false;
+        if (parent == null) {
+            if (other.parent != null)
+                return false;
+        } else if (!parent.equals(other.parent))
+            return false;
+        if (position != other.position)
+            return false;
+        if (role == null) {
+            if (other.role != null)
+                return false;
+        } else if (!role.equals(other.role))
+            return false;
+        return true;
+    }
+}
Index: unk/src/org/openstreetmap/josm/data/osm/visitor/CollectBackReferencesVisitor.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/visitor/CollectBackReferencesVisitor.java	(revision 2564)
+++ 	(revision )
@@ -1,83 +1,0 @@
-// License: GPL. Copyright 2007 by Immanuel Scholz and others
-package org.openstreetmap.josm.data.osm.visitor;
-
-import java.util.Collection;
-import java.util.HashSet;
-
-import org.openstreetmap.josm.data.osm.DataSet;
-import org.openstreetmap.josm.data.osm.Node;
-import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.Relation;
-import org.openstreetmap.josm.data.osm.Way;
-
-/**
- * Helper that collect all ways a node is part of.
- *
- * Deleted objects are not collected.
- *
- * @author imi, Petr Dlouhý
- */
-public class CollectBackReferencesVisitor extends AbstractVisitor {
-
-    private final boolean indirectRefs;
-
-    private Collection<OsmPrimitive> data = new HashSet<OsmPrimitive>();
-
-    /**
-     * @param ds This parameter is ignored
-     */
-    public CollectBackReferencesVisitor(DataSet ds) {
-        this(true);
-    }
-
-    /**
-     * @param ds This parameter is ignored
-     * @param indirectRefs Make also indirect references?
-     */
-    public CollectBackReferencesVisitor(DataSet ds, boolean indirectRefs) {
-        this.indirectRefs = indirectRefs;
-    }
-
-    public CollectBackReferencesVisitor(boolean indirectRefs) {
-        this.indirectRefs = indirectRefs;
-    }
-
-    /**
-     * Get the result collection
-     */
-    public Collection<OsmPrimitive> getData(){
-        return data;
-    }
-
-    /**
-     * Initialize data before associated visit calls
-     */
-    public void initialize(){
-        data = new HashSet<OsmPrimitive>();
-    }
-
-    public void visit(OsmPrimitive o) {
-        Collection<OsmPrimitive> c = o.getReferrers();
-        Collection<OsmPrimitive> oldData = new HashSet<OsmPrimitive>(data);
-        data.addAll(c);
-        if(indirectRefs) {
-            for(OsmPrimitive oo : c)
-                if(!oldData.contains(oo)) {
-                    visit(oo);
-                }
-        }
-
-    }
-
-    public void visit(Node n) {
-        visit((OsmPrimitive)n);
-    }
-
-    public void visit(Way w) {
-        visit((OsmPrimitive)w);
-    }
-
-    public void visit(Relation r) {
-        visit((OsmPrimitive)r);
-    }
-}
Index: /trunk/src/org/openstreetmap/josm/gui/actionsupport/DeleteFromRelationConfirmationDialog.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/actionsupport/DeleteFromRelationConfirmationDialog.java	(revision 2564)
+++ /trunk/src/org/openstreetmap/josm/gui/actionsupport/DeleteFromRelationConfirmationDialog.java	(revision 2565)
@@ -2,4 +2,5 @@
 package org.openstreetmap.josm.gui.actionsupport;
 
+import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
 import static org.openstreetmap.josm.tools.I18n.tr;
 import static org.openstreetmap.josm.tools.I18n.trn;
@@ -38,5 +39,5 @@
 import org.openstreetmap.josm.data.osm.NameFormatter;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.BackreferencedDataSet.RelationToChildReference;
+import org.openstreetmap.josm.data.osm.RelationToChildReference;
 import org.openstreetmap.josm.gui.DefaultNameFormatter;
 import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
@@ -46,5 +47,4 @@
 import org.openstreetmap.josm.tools.ImageProvider;
 import org.openstreetmap.josm.tools.WindowGeometry;
-import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
 
 /**
@@ -264,10 +264,10 @@
             RelationToChildReference ref = data.get(rowIndex);
             switch(columnIndex) {
-                case 0: return ref.getChild();
-                case 1: return ref.getParent();
-                case 2: return ref.getPosition();
-                case 3: return ref.getRole();
-                default:
-                    assert false: "Illegal column index";
+            case 0: return ref.getChild();
+            case 1: return ref.getParent();
+            case 2: return ref.getPosition();
+            case 3: return ref.getRole();
+            default:
+                assert false: "Illegal column index";
             }
             return null;
Index: /trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolverModel.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolverModel.java	(revision 2564)
+++ /trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolverModel.java	(revision 2565)
@@ -18,5 +18,5 @@
 import org.openstreetmap.josm.data.osm.Relation;
 import org.openstreetmap.josm.data.osm.RelationMember;
-import org.openstreetmap.josm.data.osm.BackreferencedDataSet.RelationToChildReference;
+import org.openstreetmap.josm.data.osm.RelationToChildReference;
 
 /**
@@ -92,9 +92,9 @@
         RelationMemberConflictDecision d = decisions.get(row);
         switch(column) {
-            case 0: /* relation */ return d.getRelation();
-            case 1: /* pos */ return Integer.toString(d.getPos() + 1); // position in "user space" starting at 1
-            case 2: /* role */ return d.getRole();
-            case 3: /* original */ return d.getOriginalPrimitive();
-            case 4: /* decision */ return d.getDecision();
+        case 0: /* relation */ return d.getRelation();
+        case 1: /* pos */ return Integer.toString(d.getPos() + 1); // position in "user space" starting at 1
+        case 2: /* role */ return d.getRole();
+        case 3: /* original */ return d.getOriginalPrimitive();
+        case 4: /* decision */ return d.getDecision();
         }
         return null;
@@ -105,11 +105,11 @@
         RelationMemberConflictDecision d = decisions.get(row);
         switch(column) {
-            case 2: /* role */
-                d.setRole((String)value);
-                break;
-            case 4: /* decision */
-                d.decide((RelationMemberConflictDecisionType)value);
-                refresh();
-                break;
+        case 2: /* role */
+            d.setRole((String)value);
+            break;
+        case 4: /* decision */
+            d.decide((RelationMemberConflictDecisionType)value);
+            refresh();
+            break;
         }
         fireTableDataChanged();
@@ -233,16 +233,16 @@
             } else {
                 switch(decision.getDecision()) {
-                    case KEEP:
-                        rmNew = new RelationMember(decision.getRole(),newPrimitive);
-                        modifiedRelation.addMember(rmNew);
-                        isChanged |= ! rm.equals(rmNew);
-                        break;
-                    case REMOVE:
-                        isChanged = true;
-                        // do nothing
-                        break;
-                    case UNDECIDED:
-                        // FIXME: this is an error
-                        break;
+                case KEEP:
+                    rmNew = new RelationMember(decision.getRole(),newPrimitive);
+                    modifiedRelation.addMember(rmNew);
+                    isChanged |= ! rm.equals(rmNew);
+                    break;
+                case REMOVE:
+                    isChanged = true;
+                    // do nothing
+                    break;
+                case UNDECIDED:
+                    // FIXME: this is an error
+                    break;
                 }
             }
@@ -278,12 +278,12 @@
             }
             switch(decision.getDecision()) {
-                case REMOVE: return true;
-                case KEEP:
-                    if (!relation.getMember(i).getRole().equals(decision.getRole()))
-                        return true;
-                    if (relation.getMember(i).getMember() != newPrimitive)
-                        return true;
-                case UNDECIDED:
-                    // FIXME: handle error
+            case REMOVE: return true;
+            case KEEP:
+                if (!relation.getMember(i).getRole().equals(decision.getRole()))
+                    return true;
+                if (relation.getMember(i).getMember() != newPrimitive)
+                    return true;
+            case UNDECIDED:
+                // FIXME: handle error
             }
         }
Index: /trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java	(revision 2564)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java	(revision 2565)
@@ -49,5 +49,4 @@
 import org.openstreetmap.josm.data.gpx.GpxTrack;
 import org.openstreetmap.josm.data.gpx.WayPoint;
-import org.openstreetmap.josm.data.osm.BackreferencedDataSet;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.DataSetMerger;
@@ -394,5 +393,4 @@
      */
     protected PurgePrimitivesCommand buildPurgeCommand() {
-        BackreferencedDataSet ds = new BackreferencedDataSet();
         ArrayList<OsmPrimitive> toPurge = new ArrayList<OsmPrimitive>();
         conflictLoop: for (Conflict<?> c: conflicts) {
@@ -416,5 +414,5 @@
                 // gets purged.
                 //
-                for (OsmPrimitive parent: ds.getParents(c.getMy())) {
+                for (OsmPrimitive parent: c.getMy().getReferrers()) {
                     if (parent.isModified() && parent instanceof Way) {
                         continue conflictLoop;
@@ -426,5 +424,4 @@
         if (toPurge.isEmpty()) return null;
         PurgePrimitivesCommand cmd = new PurgePrimitivesCommand(this, toPurge);
-        cmd.setBackreferenceDataSet(ds);
         return cmd;
     }
