Changeset - r27911:e2da1b3040ed
[Not reviewed]
master
0 1 0
PeterN - 9 months ago 2023-09-14 08:41:33
peter1138@openttd.org
Codechange: Pass by reference and use emplace-at-end for CargoSummary. (#11296)
1 file changed with 7 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/train_gui.cpp
Show inline comments
 
@@ -267,9 +267,9 @@ static void TrainDetailsCapacityTab(cons
 
 * @param v Vehicle to process
 
 * @param summary Space for the result
 
 */
 
static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary *summary)
 
static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary &summary)
 
{
 
	summary->clear();
 
	summary.clear();
 
	do {
 
		if (!v->GetEngine()->CanCarryCargo()) continue;
 

	
 
@@ -278,10 +278,9 @@ static void GetCargoSummaryOfArticulated
 
		new_item.subtype = GetCargoSubtypeText(v);
 
		if (!IsValidCargoID(new_item.cargo) && new_item.subtype == STR_EMPTY) continue;
 

	
 
		auto item = std::find(summary->begin(), summary->end(), new_item);
 
		if (item == summary->end()) {
 
			summary->emplace_back();
 
			item = summary->end() - 1;
 
		auto item = std::find(std::begin(summary), std::end(summary), new_item);
 
		if (item == std::end(summary)) {
 
			item = summary.emplace(std::end(summary));
 
			item->cargo = new_item.cargo;
 
			item->subtype = new_item.subtype;
 
			item->capacity = 0;
 
@@ -331,7 +330,7 @@ int GetTrainDetailsWndVScroll(VehicleID 
 
		num++; // needs one more because first line is description string
 
	} else {
 
		for (const Train *v = Train::Get(veh_id); v != nullptr; v = v->GetNextVehicle()) {
 
			GetCargoSummaryOfArticulatedVehicle(v, &_cargo_summary);
 
			GetCargoSummaryOfArticulatedVehicle(v, _cargo_summary);
 
			num += std::max(1u, (unsigned)_cargo_summary.size());
 

	
 
			uint length = GetLengthOfArticulatedVehicle(v);
 
@@ -363,7 +362,7 @@ void DrawTrainDetails(const Train *v, co
 
		Direction dir = rtl ? DIR_E : DIR_W;
 
		int x = rtl ? r.right : r.left;
 
		for (; v != nullptr && vscroll_pos > -vscroll_cap; v = v->GetNextVehicle()) {
 
			GetCargoSummaryOfArticulatedVehicle(v, &_cargo_summary);
 
			GetCargoSummaryOfArticulatedVehicle(v, _cargo_summary);
 

	
 
			/* Draw sprites */
 
			uint dx = 0;
0 comments (0 inline, 0 general)