From 08070e7f312d1cd458c29b22065bf8175e82b554 Mon Sep 17 00:00:00 2001 From: Herman Semenov Date: Thu, 14 Dec 2023 15:44:16 +0300 Subject: [PATCH] [Common Data/Core Dialog HLE/GPU Common Vulkan] Optimize create smart pointer using C++17 std::make_* --- Common/Data/Format/IniFile.cpp | 8 ++++---- Common/Data/Text/I18n.cpp | 2 +- Core/Dialog/SavedataParam.cpp | 2 +- Core/HLE/sceMpeg.cpp | 2 +- GPU/Common/ReplacedTexture.cpp | 2 +- GPU/Vulkan/PipelineManagerVulkan.cpp | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Common/Data/Format/IniFile.cpp b/Common/Data/Format/IniFile.cpp index a93e530f93..54396e8164 100644 --- a/Common/Data/Format/IniFile.cpp +++ b/Common/Data/Format/IniFile.cpp @@ -445,7 +445,7 @@ Section* IniFile::GetSection(const char* sectionName) { Section* IniFile::GetOrCreateSection(const char* sectionName) { Section* section = GetSection(sectionName); if (!section) { - sections.push_back(std::unique_ptr
(new Section(sectionName))); + sections.push_back(std::make_unique
(sectionName)); section = sections.back().get(); } return section; @@ -502,7 +502,7 @@ void IniFile::SortSections() bool IniFile::Load(const Path &path) { sections.clear(); - sections.push_back(std::unique_ptr
(new Section(""))); + sections.push_back(std::make_unique
("")); // first section consists of the comments before the first real section // Open file @@ -558,14 +558,14 @@ bool IniFile::Load(std::istream &in) { if (sectionNameEnd != std::string::npos) { // New section! std::string sub = line.substr(1, sectionNameEnd - 1); - sections.push_back(std::unique_ptr
(new Section(sub))); + sections.push_back(std::make_unique
(sub)); if (sectionNameEnd + 1 < line.size()) { sections.back()->comment = line.substr(sectionNameEnd + 1); } } else { if (sections.empty()) { - sections.push_back(std::unique_ptr
(new Section(""))); + sections.push_back(std::make_unique
("")); } ParsedIniLine parsedLine; parsedLine.ParseFrom(line); diff --git a/Common/Data/Text/I18n.cpp b/Common/Data/Text/I18n.cpp index 63b01a9048..f5cf79507a 100644 --- a/Common/Data/Text/I18n.cpp +++ b/Common/Data/Text/I18n.cpp @@ -58,7 +58,7 @@ void I18NRepo::Clear() { std::lock_guard guard(catsLock_); for (auto &iter : cats_) { // Initialize with empty categories, so that early lookups don't crash. - iter = std::shared_ptr(new I18NCategory()); + iter = std::make_shared(); } } diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index 58f107b218..106d3670a9 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -404,7 +404,7 @@ int SavedataParam::DeleteData(SceUtilitySavedataParam* param) { } if (changed) { - std::unique_ptr updatedList(new u8[fileListSize]); + auto updatedList = std::make_unique (fileListSize); memcpy(updatedList.get(), fileList, fileListSize); sfoFile->SetValue("SAVEDATA_FILE_LIST", updatedList.get(), fileListSize, (int)FILE_LIST_TOTAL_SIZE); diff --git a/Core/HLE/sceMpeg.cpp b/Core/HLE/sceMpeg.cpp index 8e4586a6d0..005da1d27d 100644 --- a/Core/HLE/sceMpeg.cpp +++ b/Core/HLE/sceMpeg.cpp @@ -1514,7 +1514,7 @@ void PostPutAction::run(MipsCall &call) { // It seems validation is done only by older mpeg libs. if (mpegLibVersion < 0x0105 && packetsAddedThisRound > 0) { // TODO: Faster / less wasteful validation. - std::unique_ptr demuxer(new MpegDemux(packetsAddedThisRound * 2048, 0)); + auto demuxer = std::make_unique(packetsAddedThisRound * 2048, 0); int readOffset = ringbuffer->packetsRead % (s32)ringbuffer->packets; uint32_t bufSize = Memory::ValidSize(ringbuffer->data + readOffset * 2048, packetsAddedThisRound * 2048); const u8 *buf = Memory::GetPointer(ringbuffer->data + readOffset * 2048); diff --git a/GPU/Common/ReplacedTexture.cpp b/GPU/Common/ReplacedTexture.cpp index 84fd0e2d93..ecd7661a21 100644 --- a/GPU/Common/ReplacedTexture.cpp +++ b/GPU/Common/ReplacedTexture.cpp @@ -597,7 +597,7 @@ ReplacedTexture::LoadLevelResult ReplacedTexture::LoadLevelData(VFSFileReference } else if (imageType == ReplacedImageType::ZIM) { - std::unique_ptr zim(new uint8_t[fileSize]); + auto zim = std::make_unique(fileSize); if (!zim) { ERROR_LOG(G3D, "Failed to allocate memory for texture replacement"); vfs_->CloseFile(openFile); diff --git a/GPU/Vulkan/PipelineManagerVulkan.cpp b/GPU/Vulkan/PipelineManagerVulkan.cpp index 5325027bc8..33230270c7 100644 --- a/GPU/Vulkan/PipelineManagerVulkan.cpp +++ b/GPU/Vulkan/PipelineManagerVulkan.cpp @@ -644,7 +644,7 @@ void PipelineManagerVulkan::SavePipelineCache(FILE *file, bool saveRawPipelineCa fwrite(&size, sizeof(size), 1, file); return; } - std::unique_ptr buffer(new uint8_t[dataSize]); + auto buffer = std::make_unique(dataSize); vkGetPipelineCacheData(vulkan_->GetDevice(), pipelineCache_, &dataSize, buffer.get()); size = (uint32_t)dataSize; fwrite(&size, sizeof(size), 1, file); @@ -731,7 +731,7 @@ bool PipelineManagerVulkan::LoadPipelineCache(FILE *file, bool loadRawPipelineCa WARN_LOG(G3D, "Zero-sized Vulkan pipeline cache."); return true; } - std::unique_ptr buffer(new uint8_t[size]); + auto buffer = std::make_unique(size); success = fread(buffer.get(), 1, size, file) == size; // Verify header. VkPipelineCacheHeader *header = (VkPipelineCacheHeader *)buffer.get();