Codechange: Switch DropDownList to directly use std::vector, thus making AutoDeleteSmallVector obsolete.

DropDownListItem are strongly managed using std::unique_ptr to ensure leak-free handling. Appropriate use
of move-semantics make intent a lot clearer than parameter comments and allows the compiler to generate
copy-free code for most situations.
This commit is contained in:
Michael Lutz
2019-04-02 21:31:24 +02:00
parent d3e113eb5f
commit c7b9987d08
22 changed files with 184 additions and 253 deletions

View File

@@ -2709,34 +2709,30 @@ struct IndustryCargoesWindow : public Window {
break;
case WID_IC_CARGO_DROPDOWN: {
DropDownList *lst = new DropDownList;
DropDownList lst;
const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
lst->push_back(new DropDownListStringItem(cs->name, cs->Index(), false));
lst.emplace_back(new DropDownListStringItem(cs->name, cs->Index(), false));
}
if (lst->size() == 0) {
delete lst;
break;
if (!lst.empty()) {
int selected = (this->ind_cargo >= NUM_INDUSTRYTYPES) ? (int)(this->ind_cargo - NUM_INDUSTRYTYPES) : -1;
ShowDropDownList(this, std::move(lst), selected, WID_IC_CARGO_DROPDOWN, 0, true);
}
int selected = (this->ind_cargo >= NUM_INDUSTRYTYPES) ? (int)(this->ind_cargo - NUM_INDUSTRYTYPES) : -1;
ShowDropDownList(this, lst, selected, WID_IC_CARGO_DROPDOWN, 0, true);
break;
}
case WID_IC_IND_DROPDOWN: {
DropDownList *lst = new DropDownList;
DropDownList lst;
for (uint i = 0; i < NUM_INDUSTRYTYPES; i++) {
IndustryType ind = _sorted_industry_types[i];
const IndustrySpec *indsp = GetIndustrySpec(ind);
if (!indsp->enabled) continue;
lst->push_back(new DropDownListStringItem(indsp->name, ind, false));
lst.emplace_back(new DropDownListStringItem(indsp->name, ind, false));
}
if (lst->size() == 0) {
delete lst;
break;
if (!lst.empty()) {
int selected = (this->ind_cargo < NUM_INDUSTRYTYPES) ? (int)this->ind_cargo : -1;
ShowDropDownList(this, std::move(lst), selected, WID_IC_IND_DROPDOWN, 0, true);
}
int selected = (this->ind_cargo < NUM_INDUSTRYTYPES) ? (int)this->ind_cargo : -1;
ShowDropDownList(this, lst, selected, WID_IC_IND_DROPDOWN, 0, true);
break;
}
}