Index: trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java	(revision 4056)
+++ trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java	(revision 4058)
@@ -43,7 +43,7 @@
 
     Set<MyWaySegment> ways;
-    Set<Node> endnodes; // nodes at end of way
-    Set<Node> endnodes_highway; // nodes at end of way
-    Set<Node> middlenodes; // nodes in middle of way
+    QuadBuckets<Node> endnodes; // nodes at end of way
+    QuadBuckets<Node> endnodes_highway; // nodes at end of way
+    QuadBuckets<Node> middlenodes; // nodes in middle of way
     Set<Node> othernodes; // nodes appearing at least twice
     //NodeSearchCache nodecache;
@@ -67,7 +67,7 @@
         super.startTest(monitor);
         ways = new HashSet<MyWaySegment>();
-        endnodes = new HashSet<Node>();
-        endnodes_highway = new HashSet<Node>();
-        middlenodes = new HashSet<Node>();
+        endnodes = new QuadBuckets<Node>();
+        endnodes_highway = new QuadBuckets<Node>();
+        middlenodes = new QuadBuckets<Node>();
         othernodes = new HashSet<Node>();
         mindist = Main.pref.getDouble(PREFIX + ".node_way_distance", 10.0);
@@ -94,5 +94,6 @@
                     last_print = now;
                 }
-                for (Node en : s.nearbyNodes(mindist)) {
+                Collection<Node> nearbyNodes = s.nearbyNodes(mindist);
+                for (Node en : nearbyNodes) {
                     if (en == null || !s.highway || !endnodes_highway.contains(en)) {
                         continue;
@@ -271,5 +272,6 @@
                     // area, but keep the old larger cache.
                     Set<Node> trimmed = new HashSet<Node>(nearbyNodeCache);
-                    for (Node n : new HashSet<Node>(nearbyNodeCache)) {
+                    Set<Node> initial = new HashSet<Node>(nearbyNodeCache);
+                    for (Node n : initial) {
                         if (!nearby(n, dist)) {
                             trimmed.remove(n);
@@ -290,5 +292,7 @@
             nearbyNodeCache = null;
             List<LatLon> bounds = this.getBounds(dist);
-            List<Node> found_nodes = ds.searchNodes(new BBox(bounds.get(0), bounds.get(1)));
+            List<Node> found_nodes = endnodes_highway.search(new BBox(bounds.get(0), bounds.get(1)));
+            found_nodes.addAll(endnodes.search(new BBox(bounds.get(0), bounds.get(1))));
+
             if (found_nodes == null)
                 return Collections.emptySet();
@@ -348,5 +352,5 @@
     public void visit(Way w) {
         ways.addAll(getWaySegments(w));
-        Set<Node> set = endnodes;
+        QuadBuckets<Node> set = endnodes;
         if (w.hasKey("highway") || w.hasKey("railway")) {
             set = endnodes_highway;
@@ -360,5 +364,5 @@
     }
 
-    private void addNode(Node n, Set<Node> s) {
+    private void addNode(Node n, QuadBuckets<Node> s) {
         boolean m = middlenodes.contains(n);
         boolean e = endnodes.contains(n);
