Changeset - r28202:2c4191675e85
[Not reviewed]
master
0 3 0
Peter Nelson - 12 months ago 2023-11-26 21:30:31
peter1138@openttd.org
Codechange: Use range-for to simplify getting first non-zero value.

This reduces indexed array access.
3 files changed with 6 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/script/api/script_engine.cpp
Show inline comments
 
@@ -94,9 +94,8 @@
 
		case VEH_ROAD:
 
		case VEH_TRAIN: {
 
			CargoArray capacities = GetCapacityOfArticulatedParts(engine_id);
 
			for (CargoID c = 0; c < NUM_CARGO; c++) {
 
				if (capacities[c] == 0) continue;
 
				return capacities[c];
 
			for (uint &cap : capacities) {
 
				if (cap != 0) return cap;
 
			}
 
			return -1;
 
		}
src/script/api/script_event_types.cpp
Show inline comments
 
@@ -62,9 +62,8 @@ int32_t ScriptEventEnginePreview::GetCap
 
		case VEH_ROAD:
 
		case VEH_TRAIN: {
 
			CargoArray capacities = GetCapacityOfArticulatedParts(this->engine);
 
			for (CargoID c = 0; c < NUM_CARGO; c++) {
 
				if (capacities[c] == 0) continue;
 
				return capacities[c];
 
			for (uint &cap : capacities) {
 
				if (cap != 0) return cap;
 
			}
 
			return -1;
 
		}
src/vehicle_gui.cpp
Show inline comments
 
@@ -1373,8 +1373,8 @@ static bool VehicleCargoSorter(const Veh
 
	for (v = b; v != nullptr; v = v->Next()) diff[v->cargo_type] -= v->cargo_cap;
 

	
 
	int r = 0;
 
	for (CargoID i = 0; i < NUM_CARGO; i++) {
 
		r = diff[i];
 
	for (uint d : diff) {
 
		r = d;
 
		if (r != 0) break;
 
	}
 

	
0 comments (0 inline, 0 general)