From 64930c343a9c79b060cc75427cac69b1eba90c33 Mon Sep 17 00:00:00 2001 From: PeterN Date: Sun, 14 May 2023 09:17:44 +0100 Subject: [PATCH] Codechange: Pass reference instead of pointer to GUI*Lists. (#10822) Pointer-avoidance. --- src/autoreplace_gui.cpp | 4 ++-- src/build_vehicle_gui.cpp | 8 ++++---- src/company_gui.cpp | 6 +++--- src/engine_gui.cpp | 14 +++++++------- src/engine_gui.h | 4 ++-- src/group_gui.cpp | 10 +++++----- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index cb585ebde7..f71347b516 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -195,10 +195,10 @@ class ReplaceVehicleWindow : public Window { this->sel_engine[side] = selected_engine; // update which engine we selected (the same or none, if it's not in the list anymore) if (draw_left) { - EngList_Sort(&list, &EngineNumberSorter); + EngList_Sort(list, &EngineNumberSorter); } else { _engine_sort_direction = this->descending_sort_order; - EngList_Sort(&list, _engine_sort_functions[this->window_number][this->sort_criteria]); + EngList_Sort(list, _engine_sort_functions[this->window_number][this->sort_criteria]); } this->engines[side].clear(); diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 209dd17e5b..ded2102e78 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -1430,14 +1430,14 @@ struct BuildVehicleWindow : Window { /* make engines first, and then wagons, sorted by selected sort_criteria */ _engine_sort_direction = false; - EngList_Sort(&list, TrainEnginesThenWagonsSorter); + EngList_Sort(list, TrainEnginesThenWagonsSorter); /* and then sort engines */ _engine_sort_direction = this->descending_sort_order; - EngList_SortPartial(&list, _engine_sort_functions[0][this->sort_criteria], 0, num_engines); + EngList_SortPartial(list, _engine_sort_functions[0][this->sort_criteria], 0, num_engines); /* and finally sort wagons */ - EngList_SortPartial(&list, _engine_sort_functions[0][this->sort_criteria], num_engines, list.size() - num_engines); + EngList_SortPartial(list, _engine_sort_functions[0][this->sort_criteria], num_engines, list.size() - num_engines); } /* Figure out what road vehicle EngineIDs to put in the list */ @@ -1561,7 +1561,7 @@ struct BuildVehicleWindow : Window { } _engine_sort_direction = this->descending_sort_order; - EngList_Sort(&this->eng_list, _engine_sort_functions[this->vehicle_type][this->sort_criteria]); + EngList_Sort(this->eng_list, _engine_sort_functions[this->vehicle_type][this->sort_criteria]); this->eng_list.swap(list); AddChildren(list, INVALID_ENGINE, 0); diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 37de4a8625..23967879fd 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -690,9 +690,9 @@ private: ShowDropDownList(this, std::move(list), sel, widget); } - void AddChildren(GUIGroupList *source, GroupID parent, int indent) + void AddChildren(GUIGroupList &source, GroupID parent, int indent) { - for (const Group *g : *source) { + for (const Group *g : source) { if (g->parent != parent) continue; this->groups.push_back(g); this->indents.push_back(indent); @@ -740,7 +740,7 @@ private: return r < 0; }); - AddChildren(&list, INVALID_GROUP, 0); + AddChildren(list, INVALID_GROUP, 0); } this->groups.shrink_to_fit(); diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp index 6b56ef91f9..3c995d9fa6 100644 --- a/src/engine_gui.cpp +++ b/src/engine_gui.cpp @@ -324,10 +324,10 @@ void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID eng * @param el list to be sorted * @param compare function for evaluation of the quicksort */ -void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare) +void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare) { - if (el->size() < 2) return; - std::sort(el->begin(), el->end(), compare); + if (el.size() < 2) return; + std::sort(el.begin(), el.end(), compare); } /** @@ -337,11 +337,11 @@ void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare) * @param begin start of sorting * @param num_items count of items to be sorted */ -void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, size_t begin, size_t num_items) +void EngList_SortPartial(GUIEngineList &el, EngList_SortTypeFunction compare, size_t begin, size_t num_items) { if (num_items < 2) return; - assert(begin < el->size()); - assert(begin + num_items <= el->size()); - std::sort(el->begin() + begin, el->begin() + begin + num_items, compare); + assert(begin < el.size()); + assert(begin + num_items <= el.size()); + std::sort(el.begin() + begin, el.begin() + begin + num_items, compare); } diff --git a/src/engine_gui.h b/src/engine_gui.h index 87af6f3562..b33cfaa36b 100644 --- a/src/engine_gui.h +++ b/src/engine_gui.h @@ -31,8 +31,8 @@ struct GUIEngineListItem { typedef GUIList GUIEngineList; typedef bool EngList_SortTypeFunction(const GUIEngineListItem&, const GUIEngineListItem&); ///< argument type for #EngList_Sort. -void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare); -void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, size_t begin, size_t num_items); +void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare); +void EngList_SortPartial(GUIEngineList &el, EngList_SortTypeFunction compare, size_t begin, size_t num_items); StringID GetEngineCategoryName(EngineID engine); StringID GetEngineInfoString(EngineID engine); diff --git a/src/group_gui.cpp b/src/group_gui.cpp index 1f5cb04c2f..fd2e4759ec 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -136,16 +136,16 @@ private: Dimension column_size[VGC_END]; ///< Size of the columns in the group list. - void AddChildren(GUIGroupList *source, GroupID parent, int indent) + void AddChildren(GUIGroupList &source, GroupID parent, int indent) { - for (const Group *g : *source) { + for (const Group *g : source) { if (g->parent != parent) continue; this->groups.push_back(g); this->indents.push_back(indent); if (g->folded) { /* Test if this group has children at all. If not, the folded flag should be cleared to avoid lingering unfold buttons in the list. */ - auto child = std::find_if(source->begin(), source->end(), [g](const Group *child){ return child->parent == g->index; }); - bool has_children = child != source->end(); + auto child = std::find_if(source.begin(), source.end(), [g](const Group *child){ return child->parent == g->index; }); + bool has_children = child != source.end(); Group::Get(g->index)->folded = has_children; } else { AddChildren(source, g->index, indent + 1); @@ -196,7 +196,7 @@ private: return r < 0; }); - AddChildren(&list, INVALID_GROUP, 0); + AddChildren(list, INVALID_GROUP, 0); this->groups.shrink_to_fit(); this->groups.RebuildDone();