From 8371c428cd1c3646776743f8da4bdf8c827ed487 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 22 Dec 2015 19:59:32 -0500 Subject: VertexLoaderBase: Get rid of explicit delete and new --- Source/Core/VideoCommon/VertexLoaderBase.cpp | 35 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'Source/Core/VideoCommon/VertexLoaderBase.cpp') 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; -- cgit v1.2.3