FileUtil: Add a class for Exists/IsDirectory/GetSize

Some code was calling more than one of these functions in a row
(in particular, FileUtil.cpp itself did it a lot...), which is
a waste since it's possible to call stat a single time and then
read all three values from the stat struct. This commit adds a
File::FileInfo class that calls stat once on construction and
then lets Exists/IsDirectory/GetSize be executed very quickly.

The performance improvement mostly matters for functions that
can be handling a lot of files, such as File::ScanDirectoryTree.

I've also done some cleanup in code that uses these functions.
For instance, some code had checks like !Exists() || !IsDirectory(),
which is functionally equivalent to !IsDirectory(), and some
code was using File::GetSize even though there was an IOFile
object that the code could call GetSize on.
This commit is contained in:
JosJuice
2017-06-29 11:20:38 +02:00
parent e14a82a87e
commit 5ca3aee00a
21 changed files with 175 additions and 177 deletions

View File

@ -4,6 +4,7 @@
#include "DolphinWX/ISOProperties/ISOProperties.h"
#include <algorithm>
#include <cinttypes>
#include <cstddef>
#include <cstdio>
@ -442,16 +443,12 @@ void CISOProperties::CreateGUIControls()
sButtons->GetAffirmativeButton()->SetLabel(_("Close"));
// If there is no default gameini, disable the button.
bool game_ini_exists = false;
for (const std::string& ini_filename :
SConfig::GetGameIniFilenames(game_id, m_open_iso->GetRevision()))
{
if (File::Exists(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + ini_filename))
{
game_ini_exists = true;
break;
}
}
const std::vector<std::string> ini_names =
SConfig::GetGameIniFilenames(game_id, m_open_iso->GetRevision());
const bool game_ini_exists =
std::any_of(ini_names.cbegin(), ini_names.cend(), [](const std::string& name) {
return File::Exists(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + name);
});
if (!game_ini_exists)
EditConfigDefault->Disable();