From 6ec7c619fee761fcca3052f096f576f08d9fcfc3 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sat, 13 Feb 2016 11:20:14 -0500 Subject: [PATCH] Now let's try out a few new language features... Rvalue refs, move ctor, =delete, range-for, auto, std:vector<>::emplace_back() There are also performance improvements from eliminating an indirection and using move of strings instead of copy. --- src/AboutDialog.cpp | 18 +++++------------- src/AboutDialog.h | 22 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/AboutDialog.cpp b/src/AboutDialog.cpp index e17d8378c..b75d5b803 100644 --- a/src/AboutDialog.cpp +++ b/src/AboutDialog.cpp @@ -41,9 +41,6 @@ hold information about one contributor to Audacity. #include "ShuttleGui.h" #include "widgets/LinkingHtmlWindow.h" -#include -WX_DEFINE_LIST(AboutDialogCreditItemsList); - #include "Theme.h" #include "AllThemeResources.h" @@ -209,7 +206,6 @@ AboutDialog::AboutDialog(wxWindow * parent) void AboutDialog::PopulateAudacityPage( ShuttleGui & S ) { - creditItems.DeleteContents(true); // Switch on automatic deletion of list items. CreateCreditsList(); wxString par1Str = _( @@ -866,24 +862,20 @@ wxT("POSSIBILITY OF SUCH DAMAGES.\n"); S.EndNotebookPage(); } -void AboutDialog::AddCredit(const wxString& description, Role role) +void AboutDialog::AddCredit(wxString &&description, Role role) { - AboutDialogCreditItem* item = new AboutDialogCreditItem(); - item->description = description; - item->role = role; - creditItems.Append(item); + creditItems.emplace_back(std::move(description), role); } wxString AboutDialog::GetCreditsByRole(AboutDialog::Role role) { wxString s; - for (AboutDialogCreditItemsList::compatibility_iterator p=creditItems.GetFirst(); p; p = p->GetNext()) + for (const auto &item : creditItems) { - AboutDialogCreditItem* item = p->GetData(); - if (item->role == role) + if (item.role == role) { - s += item->description; + s += item.description; s += wxT("
"); } } diff --git a/src/AboutDialog.h b/src/AboutDialog.h index 87093f14e..b4abf440f 100644 --- a/src/AboutDialog.h +++ b/src/AboutDialog.h @@ -11,6 +11,7 @@ #ifndef __AUDACITY_ABOUT_DLG__ #define __AUDACITY_ABOUT_DLG__ +#include #include #include #include @@ -21,9 +22,26 @@ class ShuttleGui; struct AboutDialogCreditItem { wxString description; int role; + + AboutDialogCreditItem(wxString &&description_, int role_) + : description(description_), role(role_) + {} + + // No copy + AboutDialogCreditItem(const AboutDialogCreditItem&) = delete; + AboutDialogCreditItem& operator= (const AboutDialogCreditItem&) = delete; + + // Move constructor, because wxString lacks one + AboutDialogCreditItem(AboutDialogCreditItem &&moveMe) + : role(moveMe.role) + { + description.swap(moveMe.description); + } + + ~AboutDialogCreditItem() {} }; -WX_DECLARE_LIST(AboutDialogCreditItem, AboutDialogCreditItemsList); +using AboutDialogCreditItemsList = std::vector; class AboutDialog:public wxDialog { DECLARE_DYNAMIC_CLASS(AboutDialog) @@ -57,7 +75,7 @@ class AboutDialog:public wxDialog { void PopulateInformationPage (ShuttleGui & S ); void CreateCreditsList(); - void AddCredit(const wxString& description, Role role); + void AddCredit(wxString &&description, Role role); wxString GetCreditsByRole(AboutDialog::Role role); void AddBuildinfoRow( wxString* htmlstring, const wxChar * libname, const wxChar * libdesc, wxString status);