Author: silene
Date: Sat May  2 15:18:45 2009
New Revision: 35414

URL: http://svn.gna.org/viewcvs/wesnoth?rev=35414&view=rev
Log:
Added precise preallocation for Dijkstra solution.

Modified:
    trunk/src/pathfind.cpp

Modified: trunk/src/pathfind.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/pathfind.cpp?rev=35414&r1=35413&r2=35414&view=diff
==============================================================================
--- trunk/src/pathfind.cpp (original)
+++ trunk/src/pathfind.cpp Sat May  2 15:18:45 2009
@@ -173,7 +173,7 @@
        indexer index(map.w(), map.h());
        comp node_comp(nodes);
 
-       int xmin = loc.x, xmax = loc.x, ymin = loc.y, ymax = loc.y;
+       int xmin = loc.x, xmax = loc.x, ymin = loc.y, ymax = loc.y, nb_dest = 1;
 
        nodes[index(loc)] = node(move_left, turns_left, 
map_location::null_location, loc);
        std::vector<int> pq;
@@ -227,12 +227,16 @@
                                if (next_visited && !(t < next)) continue;
                        }
 
-                       int x = locs[i].x;
-                       if (x < xmin) xmin = x;
-                       if (xmax < x) xmax = x;
-                       int y = locs[i].y;
-                       if (y < ymin) ymin = y;
-                       if (ymax < y) ymax = y;
+                       if (!next_visited)
+                       {
+                               ++nb_dest;
+                               int x = locs[i].x;
+                               if (x < xmin) xmin = x;
+                               if (xmax < x) xmax = x;
+                               int y = locs[i].y;
+                               if (y < ymin) ymin = y;
+                               if (ymax < y) ymax = y;
+                       }
 
                        bool in_list = next.in == search_counter + 1;
                        t.in = search_counter + 1;
@@ -250,6 +254,7 @@
 
        // Build the routes for every map_location that we reached.
        // The ordering must be compatible with map_location::operator<.
+       destinations.reserve(nb_dest);
        for (int x = xmin; x <= xmax; ++x) {
                for (int y = ymin; y <= ymax; ++y)
                {


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to