summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2012-01-01 17:32:45 +0000
committersmatz <smatz@openttd.org>2012-01-01 17:32:45 +0000
commita90b767995850d69d687aad1c7bdebed073b9295 (patch)
tree40bf8551506bb80da6d9bb96e5c2d83040f19e60
parent4af8c2d5e17fe04d0e352977993fced13e08b787 (diff)
downloadopenttd-a90b767995850d69d687aad1c7bdebed073b9295.tar.xz
(svn r23705) -Codechange: cache the last processed station in FindStationsAroundTiles() in order to make the code a bit faster
-rw-r--r--src/station_cmd.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 2086f3150..329dcfb3a 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -3407,12 +3407,19 @@ void FindStationsAroundTiles(const TileArea &location, StationList *stations)
if (max_x >= MapSizeX()) max_x = MapSizeX() - 1;
if (max_y >= MapSizeY()) max_y = MapSizeY() - 1;
+ StationID last = INVALID_STATION;
+
for (uint cy = min_y; cy < max_y; cy++) {
for (uint cx = min_x; cx < max_x; cx++) {
TileIndex cur_tile = TileXY(cx, cy);
if (!IsTileType(cur_tile, MP_STATION)) continue;
- Station *st = Station::GetByTile(cur_tile);
+ StationID sid = GetStationIndex(cur_tile);
+ /* Stop early if we met the same station again. */
+ if (sid == last) continue;
+ last = sid;
+
+ Station *st = Station::GetIfValid(sid);
/* st can be NULL in case of waypoints */
if (st == NULL) continue;