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

@@ -228,9 +228,9 @@ protected:
/**
* Builds the page selector drop down list.
*/
DropDownList *BuildDropDownList() const
DropDownList BuildDropDownList() const
{
DropDownList *list = new DropDownList();
DropDownList list;
uint16 page_num = 1;
for (const StoryPage *p : this->story_pages) {
bool current_page = p->index == this->selected_page_id;
@@ -245,16 +245,10 @@ protected:
item = str_item;
}
list->push_back(item);
list.emplace_back(item);
page_num++;
}
/* Check if list is empty. */
if (list->size() == 0) {
delete list;
list = NULL;
}
return list;
}
@@ -611,8 +605,8 @@ public:
{
switch (widget) {
case WID_SB_SEL_PAGE: {
DropDownList *list = this->BuildDropDownList();
if (list != NULL) {
DropDownList list = this->BuildDropDownList();
if (!list.empty()) {
/* Get the index of selected page. */
int selected = 0;
for (uint16 i = 0; i < this->story_pages.size(); i++) {
@@ -621,7 +615,7 @@ public:
selected++;
}
ShowDropDownList(this, list, selected, widget);
ShowDropDownList(this, std::move(list), selected, widget);
}
break;
}