altoslib: Clean up map tile removal
authorKeith Packard <keithp@keithp.com>
Sat, 20 Jun 2015 18:53:24 +0000 (11:53 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 23 Jun 2015 04:04:43 +0000 (21:04 -0700)
Remove them while walking the hash table, rather than creating a list
to remove.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosMap.java
altoslib/AltosMapTransform.java

index 1504120cfd29cd5a6196ff81414e5411e98c1ad6..59420d4b389bf7c2c4b27142419bdbd320ddd3c6 100644 (file)
@@ -280,29 +280,23 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                        upper_left = floor(transform.screen_point(new AltosPointInt(0, 0)));
                        lower_right = floor(transform.screen_point(new AltosPointInt(width(), height())));
                }
-               LinkedList<AltosPointInt> to_remove = new LinkedList<AltosPointInt>();
-
                for (AltosPointInt point : tiles.keySet()) {
                        if (point.x < upper_left.x || lower_right.x < point.x ||
                            point.y < upper_left.y || lower_right.y < point.y) {
-                               to_remove.add(point);
+                               tiles.remove(point);
                        }
                }
 
-               for (AltosPointInt point : to_remove)
-                       tiles.remove(point);
-
                cache.set_cache_size((width() / AltosMap.px_size + 2) * (height() / AltosMap.px_size + 2));
 
                for (int y = (int) upper_left.y; y <= lower_right.y; y += AltosMap.px_size) {
                        for (int x = (int) upper_left.x; x <= lower_right.x; x += AltosMap.px_size) {
-                               AltosPointInt point = new AltosPointInt(x, y);
+                               AltosPointInt   point = new AltosPointInt(x, y);
 
                                if (!tiles.containsKey(point)) {
-                                       AltosLatLon     ul = transform.lat_lon(new AltosPointDouble(x, y));
+                                       AltosLatLon     ul = transform.lat_lon(point);
                                        AltosLatLon     center = transform.lat_lon(new AltosPointDouble(x + AltosMap.px_size/2, y + AltosMap.px_size/2));
-                                       AltosMapTile tile = map_interface.new_tile(this, ul, center, zoom, maptype,
-                                                                                  px_size);
+                                       AltosMapTile tile = map_interface.new_tile(this, ul, center, zoom, maptype, px_size);
                                        tiles.put(point, tile);
                                }
                        }
index e0e8afb095af2f956b4fceddf8ba0a85f4f2a979..30994ecb60bc2dc826f50f6fffbc546b07882e24 100644 (file)
@@ -39,6 +39,10 @@ public class AltosMapTransform {
                return new AltosLatLon(lat,lon);
        }
 
+       public AltosLatLon lat_lon (AltosPointInt point) {
+               return lat_lon(new AltosPointDouble(point.x, point.y));
+       }
+
        public AltosPointDouble screen_point(AltosPointInt screen) {
                return new AltosPointDouble(screen.x + offset_x, screen.y + offset_y);
        }