diff options
author | terkhen <terkhen@openttd.org> | 2010-12-14 21:24:51 +0000 |
---|---|---|
committer | terkhen <terkhen@openttd.org> | 2010-12-14 21:24:51 +0000 |
commit | 96b98b392ad89e3d1718a7a46a3e41d4eeab61d3 (patch) | |
tree | 885c591f8823a096dcc5082d592ea8fc133a16ff | |
parent | 91df711d61168aaa109041552d8c0ff69316c632 (diff) | |
download | openttd-96b98b392ad89e3d1718a7a46a3e41d4eeab61d3.tar.xz |
(svn r21515) -Codechange: Use cached_total_length where appropiate.
-rw-r--r-- | src/ai/api/ai_vehicle.cpp | 8 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 4 |
2 files changed, 2 insertions, 10 deletions
diff --git a/src/ai/api/ai_vehicle.cpp b/src/ai/api/ai_vehicle.cpp index d7d066c7b..2aad40f60 100644 --- a/src/ai/api/ai_vehicle.cpp +++ b/src/ai/api/ai_vehicle.cpp @@ -49,13 +49,7 @@ const Vehicle *v = ::Vehicle::Get(vehicle_id); switch (v->type) { - case VEH_ROAD: { - uint total_length = 0; - for (const Vehicle *u = v; u != NULL; u = u->Next()) { - total_length += ::RoadVehicle::From(u)->rcache.cached_veh_length; - } - return total_length; - } + case VEH_ROAD: return ::RoadVehicle::From(v)->rcache.cached_total_length; case VEH_TRAIN: return ::Train::From(v)->tcache.cached_total_length; default: return -1; } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 8032b24b3..259528f4a 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -854,9 +854,7 @@ static int CDECL VehicleLengthSorter(const Vehicle * const *a, const Vehicle * c break; case VEH_ROAD: { - const RoadVehicle *u; - for (u = RoadVehicle::From(*a); u != NULL; u = u->Next()) r += u->rcache.cached_veh_length; - for (u = RoadVehicle::From(*b); u != NULL; u = u->Next()) r -= u->rcache.cached_veh_length; + r = RoadVehicle::From(*a)->rcache.cached_total_length - RoadVehicle::From(*b)->rcache.cached_total_length; break; } |