From 68091177ac6e9b7e5955077d45955c0a2146bd2c Mon Sep 17 00:00:00 2001 From: Vladislav Belov Date: Fri, 10 Apr 2026 23:03:00 +0200 Subject: [PATCH] Removes ArrayDeleter --- source/lib/allocators/shared_ptr.cpp | 66 ---------------------------- source/lib/allocators/shared_ptr.h | 15 +------ source/lib/tex/tests/test_tex.h | 8 ++-- source/lib/tex/tex.cpp | 12 ++--- source/ps/Profiler2.cpp | 3 +- 5 files changed, 13 insertions(+), 91 deletions(-) delete mode 100644 source/lib/allocators/shared_ptr.cpp diff --git a/source/lib/allocators/shared_ptr.cpp b/source/lib/allocators/shared_ptr.cpp deleted file mode 100644 index 4c9a5da070..0000000000 --- a/source/lib/allocators/shared_ptr.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* Copyright (C) 2025 Wildfire Games. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include "precompiled.h" - -#include "shared_ptr.h" - -#include "lib/allocators/allocator_checker.h" -#include "lib/debug.h" - -#ifndef NDEBUG -static AllocatorChecker s_allocatorChecker; -#endif - -class CheckedArrayDeleter -{ -public: - CheckedArrayDeleter(size_t size) - : m_size(size) - { - } - - void operator()(u8* p) - { - ENSURE(m_size != 0); -#ifndef NDEBUG - s_allocatorChecker.OnDeallocate(p, m_size); -#endif - delete[] p; - m_size = 0; - } - -private: - size_t m_size; -}; - -std::shared_ptr Allocate(size_t size) -{ - ENSURE(size != 0); - - u8* p = new u8[size]; -#ifndef NDEBUG - s_allocatorChecker.OnAllocate(p, size); -#endif - - return std::shared_ptr(p, CheckedArrayDeleter(size)); -} diff --git a/source/lib/allocators/shared_ptr.h b/source/lib/allocators/shared_ptr.h index 21f17da6bc..6a4ce76e5a 100644 --- a/source/lib/allocators/shared_ptr.h +++ b/source/lib/allocators/shared_ptr.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -46,19 +46,6 @@ inline std::shared_ptr DummySharedPtr(T* ptr) return std::shared_ptr(ptr, DummyDeleter()); } -struct ArrayDeleter -{ - template - void operator()(T* p) - { - delete[] p; - } -}; - -// (note: uses CheckedArrayDeleter) -std::shared_ptr Allocate(size_t size); - - struct AlignedDeleter { template diff --git a/source/lib/tex/tests/test_tex.h b/source/lib/tex/tests/test_tex.h index 5eca0dcb29..1b69ecaff4 100644 --- a/source/lib/tex/tests/test_tex.h +++ b/source/lib/tex/tests/test_tex.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -50,7 +50,8 @@ public: void test_img_size() { - std::shared_ptr img(new u8[100*100*4], ArrayDeleter()); + std::shared_ptr img; + TS_ASSERT_OK(AllocateAligned(img, 100 * 100 * 4)); Tex t; TS_ASSERT_OK(t.wrap(100, 100, 32, TEX_ALPHA, img, 0)); @@ -66,7 +67,8 @@ public: { const size_t w = 4, h = 4, bpp = 4; const size_t size = w*h/2; - std::shared_ptr img(new u8[size], ArrayDeleter()); + std::shared_ptr img; + TS_ASSERT_OK(AllocateAligned(img, size)); memcpy(img.get(), "\xFF\xFF\x00\x00\x00\xAA\xFF\x55", 8); // gradient from white to black const u8 expected[] = "\xFF\xFF\xFF" "\xFF\xFF\xFF" "\xFF\xFF\xFF" "\xFF\xFF\xFF" diff --git a/source/lib/tex/tex.cpp b/source/lib/tex/tex.cpp index 21c727b667..2c83805ee4 100644 --- a/source/lib/tex/tex.cpp +++ b/source/lib/tex/tex.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -653,11 +653,11 @@ u32 Tex::get_average_color() const // construct a new texture based on the current one, // but only include the last mipmap level // do this so that we can use the general conversion methods for the pixel data - Tex basetex = *this; - uint8_t *data = new uint8_t[last_level_size]; - memcpy(data, m_Data.get() + m_Ofs + size - last_level_size, last_level_size); - std::shared_ptr sdata(data, ArrayDeleter()); - basetex.wrap(1, 1, m_Bpp, m_Flags, sdata, 0); + Tex basetex; + std::shared_ptr data; + WARN_IF_ERR(AllocateAligned(data, last_level_size)); + memcpy(data.get(), m_Data.get() + m_Ofs + size - last_level_size, last_level_size); + basetex.wrap(1, 1, m_Bpp, m_Flags, data, 0); // convert to BGRA WARN_IF_ERR(basetex.transform_to(TEX_BGR | TEX_ALPHA)); diff --git a/source/ps/Profiler2.cpp b/source/ps/Profiler2.cpp index f1fbaf3808..2c9eb8fb78 100644 --- a/source/ps/Profiler2.cpp +++ b/source/ps/Profiler2.cpp @@ -24,7 +24,6 @@ #include "Profiler2.h" -#include "lib/allocators/shared_ptr.h" #include "lib/code_generation.h" #include "lib/os_path.h" #include "lib/path.h" @@ -304,7 +303,7 @@ std::string CProfiler2::ThreadStorage::GetBuffer() // // See comments on m_BufferPos0 etc. - std::shared_ptr buffer(new u8[BUFFER_SIZE], ArrayDeleter()); + std::unique_ptr buffer{std::make_unique(BUFFER_SIZE)}; u32 pos1 = m_BufferPos1; COMPILER_FENCE; // must read m_BufferPos1 before m_Buffer