From 6e0e4646bd37d88820a4b52a5896a7078d6521ec Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 30 Sep 2016 03:13:12 -0400 Subject: [PATCH 1/2] GameListCtrl: use unique_ptr for underlying game list items --- Source/Core/DolphinWX/GameListCtrl.cpp | 17 ++++++++--------- Source/Core/DolphinWX/GameListCtrl.h | 13 +++---------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index cbbd4ad6b7..0656209c72 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -177,7 +177,6 @@ CGameListCtrl::CGameListCtrl(wxWindow* parent, const wxWindowID id, const wxPoin CGameListCtrl::~CGameListCtrl() { - ClearIsoFiles(); } template @@ -648,7 +647,7 @@ void CGameListCtrl::ScanForISOs() } if (list) - m_ISOFiles.push_back(iso_file.release()); + m_ISOFiles.push_back(std::move(iso_file)); } } } @@ -662,7 +661,7 @@ void CGameListCtrl::ScanForISOs() auto gli = std::make_unique(drive, custom_title_map); if (gli->IsValid()) - m_ISOFiles.push_back(gli.release()); + m_ISOFiles.push_back(std::move(gli)); } } @@ -715,7 +714,7 @@ void CGameListCtrl::OnColBeginDrag(wxListEvent& event) const GameListItem* CGameListCtrl::GetISO(size_t index) const { if (index < m_ISOFiles.size()) - return m_ISOFiles[index]; + return m_ISOFiles[index].get(); else return nullptr; } @@ -850,10 +849,10 @@ void CGameListCtrl::OnMouseMotion(wxMouseEvent& event) // Emulation status static const char* const emuState[] = {"Broken", "Intro", "In-Game", "Playable", "Perfect"}; - const GameListItem& rISO = *m_ISOFiles[GetItemData(item)]; + const GameListItem* iso = m_ISOFiles[GetItemData(item)].get(); - const int emu_state = rISO.GetEmuState(); - const std::string& issues = rISO.GetIssues(); + const int emu_state = iso->GetEmuState(); + const std::string& issues = iso->GetIssues(); // Show a tooltip containing the EmuState and the state description if (emu_state > 0 && emu_state < 6) @@ -997,7 +996,7 @@ const GameListItem* CGameListCtrl::GetSelectedISO() const long item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (item == wxNOT_FOUND) return nullptr; - return m_ISOFiles[GetItemData(item)]; + return m_ISOFiles[GetItemData(item)].get(); } } @@ -1010,7 +1009,7 @@ std::vector CGameListCtrl::GetAllSelectedISOs() const item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (item == wxNOT_FOUND) return result; - result.push_back(m_ISOFiles[GetItemData(item)]); + result.push_back(m_ISOFiles[GetItemData(item)].get()); } } diff --git a/Source/Core/DolphinWX/GameListCtrl.h b/Source/Core/DolphinWX/GameListCtrl.h index 4c23aa5941..09f91eca99 100644 --- a/Source/Core/DolphinWX/GameListCtrl.h +++ b/Source/Core/DolphinWX/GameListCtrl.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include @@ -65,17 +66,9 @@ private: std::vector m_FlagImageIndex; std::vector m_PlatformImageIndex; std::vector m_EmuStateImageIndex; - std::vector m_ISOFiles; - - void ClearIsoFiles() - { - while (!m_ISOFiles.empty()) // so lazy - { - delete m_ISOFiles.back(); - m_ISOFiles.pop_back(); - } - } + std::vector> m_ISOFiles; + void ClearIsoFiles() { m_ISOFiles.clear(); } int last_column; int last_sort; wxSize lastpos; From d8e4d5f0358e4098547f0ddea18f13f055b2e810 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 30 Sep 2016 03:16:43 -0400 Subject: [PATCH 2/2] GameListCtrl: eliminate redundant elses These aren't necessary considering the above condition returns --- Source/Core/DolphinWX/GameListCtrl.cpp | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index 0656209c72..39ed2d4e9d 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -715,8 +715,8 @@ const GameListItem* CGameListCtrl::GetISO(size_t index) const { if (index < m_ISOFiles.size()) return m_ISOFiles[index].get(); - else - return nullptr; + + return nullptr; } static CGameListCtrl* caller; @@ -983,21 +983,17 @@ void CGameListCtrl::OnRightClick(wxMouseEvent& event) const GameListItem* CGameListCtrl::GetSelectedISO() const { - if (m_ISOFiles.size() == 0) - { + if (m_ISOFiles.empty()) return nullptr; - } - else if (GetSelectedItemCount() == 0) - { + + if (GetSelectedItemCount() == 0) return nullptr; - } - else - { - long item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); - if (item == wxNOT_FOUND) - return nullptr; - return m_ISOFiles[GetItemData(item)].get(); - } + + long item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + if (item == wxNOT_FOUND) + return nullptr; + + return m_ISOFiles[GetItemData(item)].get(); } std::vector CGameListCtrl::GetAllSelectedISOs() const