diff options
author | Michael Lutz <michi@icosahedron.de> | 2019-04-02 21:31:24 +0200 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2019-04-09 22:45:15 +0200 |
commit | c7b9987d081ae4e0103309b18c93deecc395dec9 (patch) | |
tree | e5b1f9553d6399e2eed9c05a2d91673205f9c912 /src/story_gui.cpp | |
parent | d3e113eb5f618ce0174fa0dfa2591cb96e999350 (diff) | |
download | openttd-c7b9987d081ae4e0103309b18c93deecc395dec9.tar.xz |
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.
Diffstat (limited to 'src/story_gui.cpp')
-rw-r--r-- | src/story_gui.cpp | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/story_gui.cpp b/src/story_gui.cpp index 5679bbdc6..c90992c6b 100644 --- a/src/story_gui.cpp +++ b/src/story_gui.cpp @@ -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; } |