From 157a305507cbeac1d1557f0d7767dc57807c1945 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 27 May 2019 12:45:21 -0400 Subject: [PATCH] UICommon/ResourcePack: Deduplicate string construction A few cases duplicate the string patch creation, which is kind of wasteful. We can just construct the string once. --- Source/Core/UICommon/ResourcePack/ResourcePack.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Core/UICommon/ResourcePack/ResourcePack.cpp b/Source/Core/UICommon/ResourcePack/ResourcePack.cpp index 29bf41c9e0..5a5e443912 100644 --- a/Source/Core/UICommon/ResourcePack/ResourcePack.cpp +++ b/Source/Core/UICommon/ResourcePack/ResourcePack.cpp @@ -197,9 +197,9 @@ bool ResourcePack::Install(const std::string& path) return false; } + const std::string texture_path = path + TEXTURE_PATH + texture; std::string m_full_dir; - - SplitPath(path + TEXTURE_PATH + texture, &m_full_dir, nullptr, nullptr); + SplitPath(texture_path, &m_full_dir, nullptr, nullptr); if (!File::CreateFullPath(m_full_dir)) { @@ -217,7 +217,7 @@ bool ResourcePack::Install(const std::string& path) return false; } - std::ofstream out(path + TEXTURE_PATH + texture, std::ios::trunc | std::ios::binary); + std::ofstream out(texture_path, std::ios::trunc | std::ios::binary); if (!out.good()) { @@ -284,7 +284,8 @@ bool ResourcePack::Uninstall(const std::string& path) if (provided_by_other_pack) continue; - if (File::Exists(path + TEXTURE_PATH + texture) && !File::Delete(path + TEXTURE_PATH + texture)) + const std::string texture_path = path + TEXTURE_PATH + texture; + if (File::Exists(texture_path) && !File::Delete(texture_path)) { m_error = "Failed to delete texture " + texture; return false; @@ -293,8 +294,7 @@ bool ResourcePack::Uninstall(const std::string& path) // Recursively delete empty directories std::string dir; - - SplitPath(path + TEXTURE_PATH + texture, &dir, nullptr, nullptr); + SplitPath(texture_path, &dir, nullptr, nullptr); while (dir.length() > (path + TEXTURE_PATH).length()) {