Skip to content

Commit

Permalink
UICommon/ResourcePack: Deduplicate string construction
Browse files Browse the repository at this point in the history
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 157a305
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Source/Core/UICommon/ResourcePack/ResourcePack.cpp
Expand Up @@ -197,9 +197,9 @@ bool ResourcePack::Install(const std::string& path)
return false; return false;
} }


const std::string texture_path = path + TEXTURE_PATH + texture;
std::string m_full_dir; std::string m_full_dir;

SplitPath(texture_path, &m_full_dir, nullptr, nullptr);
SplitPath(path + TEXTURE_PATH + texture, &m_full_dir, nullptr, nullptr);


if (!File::CreateFullPath(m_full_dir)) if (!File::CreateFullPath(m_full_dir))
{ {
Expand All @@ -217,7 +217,7 @@ bool ResourcePack::Install(const std::string& path)
return false; 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()) if (!out.good())
{ {
Expand Down Expand Up @@ -284,7 +284,8 @@ bool ResourcePack::Uninstall(const std::string& path)
if (provided_by_other_pack) if (provided_by_other_pack)
continue; 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; m_error = "Failed to delete texture " + texture;
return false; return false;
Expand All @@ -293,8 +294,7 @@ bool ResourcePack::Uninstall(const std::string& path)
// Recursively delete empty directories // Recursively delete empty directories


std::string dir; std::string dir;

SplitPath(texture_path, &dir, nullptr, nullptr);
SplitPath(path + TEXTURE_PATH + texture, &dir, nullptr, nullptr);


while (dir.length() > (path + TEXTURE_PATH).length()) while (dir.length() > (path + TEXTURE_PATH).length())
{ {
Expand Down

0 comments on commit 157a305

Please sign in to comment.