Skip to content
Permalink
Browse files

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.
  • Loading branch information...
lioncash committed May 27, 2019
1 parent a22cc61 commit 157a305507cbeac1d1557f0d7767dc57807c1945
Showing with 6 additions and 6 deletions.
  1. +6 −6 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())
{

0 comments on commit 157a305

Please sign in to comment.
You can’t perform that action at this time.