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

@@ -68,21 +68,21 @@ struct SetDateWindow : Window {
void ShowDateDropDown(int widget)
{
int selected;
DropDownList *list = new DropDownList();
DropDownList list;
switch (widget) {
default: NOT_REACHED();
case WID_SD_DAY:
for (uint i = 0; i < 31; i++) {
list->push_back(new DropDownListStringItem(STR_DAY_NUMBER_1ST + i, i + 1, false));
list.emplace_back(new DropDownListStringItem(STR_DAY_NUMBER_1ST + i, i + 1, false));
}
selected = this->date.day;
break;
case WID_SD_MONTH:
for (uint i = 0; i < 12; i++) {
list->push_back(new DropDownListStringItem(STR_MONTH_JAN + i, i, false));
list.emplace_back(new DropDownListStringItem(STR_MONTH_JAN + i, i, false));
}
selected = this->date.month;
break;
@@ -91,13 +91,13 @@ struct SetDateWindow : Window {
for (Year i = this->min_year; i <= this->max_year; i++) {
DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false);
item->SetParam(0, i);
list->push_back(item);
list.emplace_back(item);
}
selected = this->date.year;
break;
}
ShowDropDownList(this, list, selected, widget);
ShowDropDownList(this, std::move(list), selected, widget);
}
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override