Skip to content

Commit

Permalink
Merge pull request #18546 from GermanAizek/make-smart-ptr
Browse files Browse the repository at this point in the history
[Common Data/Core Dialog HLE/GPU Common Vulkan] Optimize create smart pointers using C++17 std::make_*
  • Loading branch information
hrydgard committed Dec 14, 2023
2 parents b78c7ad + 08070e7 commit ebaebf5
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions Common/Data/Format/IniFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Section>(new Section(sectionName)));
sections.push_back(std::make_unique<Section>(sectionName));
section = sections.back().get();
}
return section;
Expand Down Expand Up @@ -502,7 +502,7 @@ void IniFile::SortSections()
bool IniFile::Load(const Path &path)
{
sections.clear();
sections.push_back(std::unique_ptr<Section>(new Section("")));
sections.push_back(std::make_unique<Section>(""));
// first section consists of the comments before the first real section

// Open file
Expand Down Expand Up @@ -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<Section>(new Section(sub)));
sections.push_back(std::make_unique<Section>(sub));

if (sectionNameEnd + 1 < line.size()) {
sections.back()->comment = line.substr(sectionNameEnd + 1);
}
} else {
if (sections.empty()) {
sections.push_back(std::unique_ptr<Section>(new Section("")));
sections.push_back(std::make_unique<Section>(""));
}
ParsedIniLine parsedLine;
parsedLine.ParseFrom(line);
Expand Down
2 changes: 1 addition & 1 deletion Common/Data/Text/I18n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void I18NRepo::Clear() {
std::lock_guard<std::mutex> guard(catsLock_);
for (auto &iter : cats_) {
// Initialize with empty categories, so that early lookups don't crash.
iter = std::shared_ptr<I18NCategory>(new I18NCategory());
iter = std::make_shared<I18NCategory>();
}
}

Expand Down
2 changes: 1 addition & 1 deletion Core/Dialog/SavedataParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ int SavedataParam::DeleteData(SceUtilitySavedataParam* param) {
}

if (changed) {
std::unique_ptr<u8[]> updatedList(new u8[fileListSize]);
auto updatedList = std::make_unique<u8[]> (fileListSize);
memcpy(updatedList.get(), fileList, fileListSize);
sfoFile->SetValue("SAVEDATA_FILE_LIST", updatedList.get(), fileListSize, (int)FILE_LIST_TOTAL_SIZE);

Expand Down
2 changes: 1 addition & 1 deletion Core/HLE/sceMpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MpegDemux> demuxer(new MpegDemux(packetsAddedThisRound * 2048, 0));
auto demuxer = std::make_unique<MpegDemux>(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);
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/ReplacedTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ ReplacedTexture::LoadLevelResult ReplacedTexture::LoadLevelData(VFSFileReference

} else if (imageType == ReplacedImageType::ZIM) {

std::unique_ptr<uint8_t[]> zim(new uint8_t[fileSize]);
auto zim = std::make_unique<uint8_t[]>(fileSize);
if (!zim) {
ERROR_LOG(G3D, "Failed to allocate memory for texture replacement");
vfs_->CloseFile(openFile);
Expand Down
4 changes: 2 additions & 2 deletions GPU/Vulkan/PipelineManagerVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ void PipelineManagerVulkan::SavePipelineCache(FILE *file, bool saveRawPipelineCa
fwrite(&size, sizeof(size), 1, file);
return;
}
std::unique_ptr<uint8_t[]> buffer(new uint8_t[dataSize]);
auto buffer = std::make_unique<uint8_t[]>(dataSize);
vkGetPipelineCacheData(vulkan_->GetDevice(), pipelineCache_, &dataSize, buffer.get());
size = (uint32_t)dataSize;
fwrite(&size, sizeof(size), 1, file);
Expand Down Expand Up @@ -731,7 +731,7 @@ bool PipelineManagerVulkan::LoadPipelineCache(FILE *file, bool loadRawPipelineCa
WARN_LOG(G3D, "Zero-sized Vulkan pipeline cache.");
return true;
}
std::unique_ptr<uint8_t[]> buffer(new uint8_t[size]);
auto buffer = std::make_unique<uint8_t[]>(size);
success = fread(buffer.get(), 1, size, file) == size;
// Verify header.
VkPipelineCacheHeader *header = (VkPipelineCacheHeader *)buffer.get();
Expand Down

0 comments on commit ebaebf5

Please sign in to comment.