From 8371c428cd1c3646776743f8da4bdf8c827ed487 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 22 Dec 2015 19:59:32 -0500 Subject: [PATCH] VertexLoaderBase: Get rid of explicit delete and new --- .../VideoBackends/Software/SWVertexLoader.cpp | 4 +-- Source/Core/VideoCommon/VertexLoaderBase.cpp | 35 +++++++++---------- Source/Core/VideoCommon/VertexLoaderBase.h | 3 +- .../Core/VideoCommon/VertexLoaderManager.cpp | 4 +-- .../VideoCommon/VertexLoaderTest.cpp | 2 +- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Source/Core/VideoBackends/Software/SWVertexLoader.cpp b/Source/Core/VideoBackends/Software/SWVertexLoader.cpp index 260c0b1d41..c42e797a67 100644 --- a/Source/Core/VideoBackends/Software/SWVertexLoader.cpp +++ b/Source/Core/VideoBackends/Software/SWVertexLoader.cpp @@ -44,8 +44,8 @@ void SWVertexLoader::SetFormat(u8 attributeIndex, u8 primitiveType) if (!m_CurrentLoader) { - m_CurrentLoader = VertexLoaderBase::CreateVertexLoader(g_main_cp_state.vtx_desc, g_main_cp_state.vtx_attr[m_attributeIndex]); - m_VertexLoaderMap[uid] = std::unique_ptr(m_CurrentLoader); + m_VertexLoaderMap[uid] = VertexLoaderBase::CreateVertexLoader(g_main_cp_state.vtx_desc, g_main_cp_state.vtx_attr[m_attributeIndex]); + m_CurrentLoader = m_VertexLoaderMap[uid].get(); } m_VertexSize = m_CurrentLoader->m_VertexSize; diff --git a/Source/Core/VideoCommon/VertexLoaderBase.cpp b/Source/Core/VideoCommon/VertexLoaderBase.cpp index 7db8c22b8a..94d4f600ae 100644 --- a/Source/Core/VideoCommon/VertexLoaderBase.cpp +++ b/Source/Core/VideoCommon/VertexLoaderBase.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include "Common/Common.h" @@ -130,8 +131,8 @@ void VertexLoaderBase::AppendToString(std::string *dest) const class VertexLoaderTester : public VertexLoaderBase { public: - VertexLoaderTester(VertexLoaderBase* _a, VertexLoaderBase* _b, const TVtxDesc& vtx_desc, const VAT& vtx_attr) - : VertexLoaderBase(vtx_desc, vtx_attr), a(_a), b(_b) + VertexLoaderTester(std::unique_ptr a_, std::unique_ptr b_, const TVtxDesc& vtx_desc, const VAT& vtx_attr) + : VertexLoaderBase(vtx_desc, vtx_attr), a(std::move(a_)), b(std::move(b_)) { m_initialized = a && b && a->IsInitialized() && b->IsInitialized(); @@ -159,8 +160,6 @@ public: } ~VertexLoaderTester() override { - delete a; - delete b; } int RunVertices(DataReader src, DataReader dst, int count) override @@ -187,43 +186,43 @@ public: bool IsInitialized() override { return m_initialized; } private: - VertexLoaderBase *a, *b; bool m_initialized; - std::vector buffer_a, buffer_b; + + std::unique_ptr a; + std::unique_ptr b; + + std::vector buffer_a; + std::vector buffer_b; }; -VertexLoaderBase* VertexLoaderBase::CreateVertexLoader(const TVtxDesc& vtx_desc, const VAT& vtx_attr) +std::unique_ptr VertexLoaderBase::CreateVertexLoader(const TVtxDesc& vtx_desc, const VAT& vtx_attr) { - VertexLoaderBase* loader; + std::unique_ptr loader; //#define COMPARE_VERTEXLOADERS #if defined(COMPARE_VERTEXLOADERS) && defined(_M_X86_64) // first try: Any new VertexLoader vs the old one - loader = new VertexLoaderTester( - new VertexLoader(vtx_desc, vtx_attr), // the software one - new VertexLoaderX64(vtx_desc, vtx_attr), // the new one to compare + loader = std::make_unique( + std::make_unique(vtx_desc, vtx_attr), // the software one + std::make_unique(vtx_desc, vtx_attr), // the new one to compare vtx_desc, vtx_attr); if (loader->IsInitialized()) return loader; - delete loader; #elif defined(_M_X86_64) - loader = new VertexLoaderX64(vtx_desc, vtx_attr); + loader = std::make_unique(vtx_desc, vtx_attr); if (loader->IsInitialized()) return loader; - delete loader; #elif defined(_M_ARM_64) - loader = new VertexLoaderARM64(vtx_desc, vtx_attr); + loader = std::make_unique(vtx_desc, vtx_attr); if (loader->IsInitialized()) return loader; - delete loader; #endif // last try: The old VertexLoader - loader = new VertexLoader(vtx_desc, vtx_attr); + loader = std::make_unique(vtx_desc, vtx_attr); if (loader->IsInitialized()) return loader; - delete loader; PanicAlert("No Vertex Loader found."); return nullptr; diff --git a/Source/Core/VideoCommon/VertexLoaderBase.h b/Source/Core/VideoCommon/VertexLoaderBase.h index 46f7509c0f..e7b7357e7b 100644 --- a/Source/Core/VideoCommon/VertexLoaderBase.h +++ b/Source/Core/VideoCommon/VertexLoaderBase.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include "Common/CommonTypes.h" @@ -71,7 +72,7 @@ template <> struct hash class VertexLoaderBase { public: - static VertexLoaderBase* CreateVertexLoader(const TVtxDesc &vtx_desc, const VAT &vtx_attr); + static std::unique_ptr CreateVertexLoader(const TVtxDesc &vtx_desc, const VAT &vtx_attr); virtual ~VertexLoaderBase() {} virtual int RunVertices(DataReader src, DataReader dst, int count) = 0; diff --git a/Source/Core/VideoCommon/VertexLoaderManager.cpp b/Source/Core/VideoCommon/VertexLoaderManager.cpp index 25c4c6adb0..baf04ba52a 100644 --- a/Source/Core/VideoCommon/VertexLoaderManager.cpp +++ b/Source/Core/VideoCommon/VertexLoaderManager.cpp @@ -141,8 +141,8 @@ static VertexLoaderBase* RefreshLoader(int vtx_attr_group, bool preprocess = fal } else { - loader = VertexLoaderBase::CreateVertexLoader(state->vtx_desc, state->vtx_attr[vtx_attr_group]); - s_vertex_loader_map[uid] = std::unique_ptr(loader); + s_vertex_loader_map[uid] = VertexLoaderBase::CreateVertexLoader(state->vtx_desc, state->vtx_attr[vtx_attr_group]); + loader = s_vertex_loader_map[uid].get(); INCSTAT(stats.numVertexLoaders); } if (check_for_native_format) diff --git a/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp b/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp index 84e1029e2e..9ca8befc95 100644 --- a/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp +++ b/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp @@ -61,7 +61,7 @@ protected: void CreateAndCheckSizes(size_t input_size, size_t output_size) { - m_loader.reset(VertexLoaderBase::CreateVertexLoader(m_vtx_desc, m_vtx_attr)); + m_loader = VertexLoaderBase::CreateVertexLoader(m_vtx_desc, m_vtx_attr); ASSERT_EQ((int)input_size, m_loader->m_VertexSize); ASSERT_EQ((int)output_size, m_loader->m_native_vtx_decl.stride); }