Codechange: Avoid emplace_back(new()) into a unique_ptr. (#11384)

This could theoretically leave an unmanaged pointer in certain circumstances, and directly using
make_unique shows intent.
This commit is contained in:
Peter Nelson
2023-10-20 18:40:48 +01:00
committed by GitHub
parent 429a6f58e7
commit fd6f1e844a
21 changed files with 117 additions and 118 deletions

View File

@@ -392,7 +392,7 @@ struct NewGRFParametersWindow : public Window {
DropDownList list;
for (uint32_t i = par_info.min_value; i <= par_info.max_value; i++) {
list.emplace_back(new DropDownListStringItem(GetGRFStringFromGRFText(par_info.value_names.find(i)->second), i, false));
list.push_back(std::make_unique<DropDownListStringItem>(GetGRFStringFromGRFText(par_info.value_names.find(i)->second), i, false));
}
ShowDropDownListAt(this, std::move(list), old_val, WID_NP_SETTING_DROPDOWN, wi_rect, COLOUR_ORANGE);
@@ -952,10 +952,10 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
DropDownList list;
/* Add 'None' option for clearing list */
list.emplace_back(new DropDownListStringItem(STR_NONE, -1, false));
list.push_back(std::make_unique<DropDownListStringItem>(STR_NONE, -1, false));
for (uint i = 0; i < this->grf_presets.size(); i++) {
list.emplace_back(new DropDownListStringItem(this->grf_presets[i], i, false));
list.push_back(std::make_unique<DropDownListStringItem>(this->grf_presets[i], i, false));
}
this->CloseChildWindows(WC_QUERY_STRING); // Remove the parameter query window