pointless micro optimisations

This commit is contained in:
RSDuck 2023-04-28 17:05:34 +02:00
parent 3ada5b9bc8
commit 4b170b94d5
19 changed files with 87 additions and 73 deletions

View File

@ -28,7 +28,7 @@ using Platform::LogLevel;
// TODO: more user-friendly error reporting
ARCodeFile::ARCodeFile(std::string filename)
ARCodeFile::ARCodeFile(const std::string& filename)
{
Filename = filename;

View File

@ -46,7 +46,7 @@ typedef std::list<ARCodeCat> ARCodeCatList;
class ARCodeFile
{
public:
ARCodeFile(std::string filename);
ARCodeFile(const std::string& filename);
~ARCodeFile();
bool Error;

View File

@ -769,7 +769,7 @@ void DSi_SDHost::CheckSwapFIFO()
#define MMC_DESC (Internal?"NAND":"SDcard")
DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, std::string filename)
DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, const std::string& filename)
: DSi_SDDevice(host)
{
Internal = internal;
@ -780,7 +780,7 @@ DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, std::string file
ReadOnly = false;
}
DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, std::string filename, u64 size, bool readonly, std::string sourcedir)
DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, const std::string& filename, u64 size, bool readonly, const std::string& sourcedir)
: DSi_SDDevice(host)
{
Internal = internal;

View File

@ -125,8 +125,8 @@ protected:
class DSi_MMCStorage : public DSi_SDDevice
{
public:
DSi_MMCStorage(DSi_SDHost* host, bool internal, std::string filename);
DSi_MMCStorage(DSi_SDHost* host, bool internal, std::string filename, u64 size, bool readonly, std::string sourcedir);
DSi_MMCStorage(DSi_SDHost* host, bool internal, const std::string& filename);
DSi_MMCStorage(DSi_SDHost* host, bool internal, const std::string& filename, u64 size, bool readonly, const std::string& sourcedir);
~DSi_MMCStorage();
void Reset();

View File

@ -37,7 +37,7 @@ namespace fs = std::filesystem;
#endif // __WIN32__
FATStorage::FATStorage(std::string filename, u64 size, bool readonly, std::string sourcedir)
FATStorage::FATStorage(const std::string& filename, u64 size, bool readonly, const std::string& sourcedir)
{
ReadOnly = readonly;
Load(filename, size, sourcedir);
@ -69,7 +69,7 @@ void FATStorage::Close()
}
bool FATStorage::InjectFile(std::string path, u8* data, u32 len)
bool FATStorage::InjectFile(const std::string& path, u8* data, u32 len)
{
if (!File) return false;
if (FF_File) return false;
@ -89,9 +89,10 @@ bool FATStorage::InjectFile(std::string path, u8* data, u32 len)
return false;
}
path = "0:/" + path;
std::string prefixedPath("0:/");
prefixedPath += path;
FF_FIL file;
res = f_open(&file, path.c_str(), FA_CREATE_ALWAYS | FA_WRITE);
res = f_open(&file, prefixedPath.c_str(), FA_CREATE_ALWAYS | FA_WRITE);
if (res != FR_OK)
{
f_unmount("0:");
@ -345,7 +346,7 @@ void FATStorage::SaveIndex()
}
bool FATStorage::ExportFile(std::string path, fs::path out)
bool FATStorage::ExportFile(const std::string& path, fs::path out)
{
FF_FIL file;
FILE* fout;
@ -393,7 +394,7 @@ bool FATStorage::ExportFile(std::string path, fs::path out)
return true;
}
void FATStorage::ExportDirectory(std::string path, std::string outbase, int level)
void FATStorage::ExportDirectory(const std::string& path, const std::string& outbase, int level)
{
if (level >= 32) return;
@ -492,7 +493,7 @@ void FATStorage::ExportDirectory(std::string path, std::string outbase, int leve
}
}
bool FATStorage::DeleteHostDirectory(std::string path, std::string outbase, int level)
bool FATStorage::DeleteHostDirectory(const std::string& path, const std::string& outbase, int level)
{
if (level >= 32) return false;
@ -565,7 +566,7 @@ bool FATStorage::DeleteHostDirectory(std::string path, std::string outbase, int
return true;
}
void FATStorage::ExportChanges(std::string outbase)
void FATStorage::ExportChanges(const std::string& outbase)
{
// reflect changes in the FAT volume to the host filesystem
// * delete directories and files that exist in the index but not in the volume
@ -652,7 +653,7 @@ bool FATStorage::CanFitFile(u32 len)
return (freeclusters >= len);
}
bool FATStorage::DeleteDirectory(std::string path, int level)
bool FATStorage::DeleteDirectory(const std::string& path, int level)
{
if (level >= 32) return false;
if (path.length() < 1) return false;
@ -710,7 +711,7 @@ bool FATStorage::DeleteDirectory(std::string path, int level)
return true;
}
void FATStorage::CleanupDirectory(std::string sourcedir, std::string path, int level)
void FATStorage::CleanupDirectory(const std::string& sourcedir, const std::string& path, int level)
{
if (level >= 32) return;
@ -778,7 +779,7 @@ void FATStorage::CleanupDirectory(std::string sourcedir, std::string path, int l
}
}
bool FATStorage::ImportFile(std::string path, fs::path in)
bool FATStorage::ImportFile(const std::string& path, fs::path in)
{
FF_FIL file;
FILE* fin;
@ -825,7 +826,7 @@ bool FATStorage::ImportFile(std::string path, fs::path in)
return true;
}
bool FATStorage::ImportDirectory(std::string sourcedir)
bool FATStorage::ImportDirectory(const std::string& sourcedir)
{
// remove whatever isn't in the index
CleanupDirectory(sourcedir, "", 0);
@ -938,7 +939,7 @@ u64 FATStorage::GetDirectorySize(fs::path sourcedir)
return ret;
}
bool FATStorage::Load(std::string filename, u64 size, std::string sourcedir)
bool FATStorage::Load(const std::string& filename, u64 size, const std::string& sourcedir)
{
FilePath = filename;
FileSize = size;

View File

@ -31,13 +31,13 @@
class FATStorage
{
public:
FATStorage(std::string filename, u64 size, bool readonly, std::string sourcedir);
FATStorage(const std::string& filename, u64 size, bool readonly, const std::string& sourcedir);
~FATStorage();
bool Open();
void Close();
bool InjectFile(std::string path, u8* data, u32 len);
bool InjectFile(const std::string& path, u8* data, u32 len);
u32 ReadSectors(u32 start, u32 num, u8* data);
u32 WriteSectors(u32 start, u32 num, u8* data);
@ -62,19 +62,19 @@ private:
void LoadIndex();
void SaveIndex();
bool ExportFile(std::string path, std::filesystem::path out);
void ExportDirectory(std::string path, std::string outbase, int level);
bool DeleteHostDirectory(std::string path, std::string outbase, int level);
void ExportChanges(std::string outbase);
bool ExportFile(const std::string& path, std::filesystem::path out);
void ExportDirectory(const std::string& path, const std::string& outbase, int level);
bool DeleteHostDirectory(const std::string& path, const std::string& outbase, int level);
void ExportChanges(const std::string& outbase);
bool CanFitFile(u32 len);
bool DeleteDirectory(std::string path, int level);
void CleanupDirectory(std::string sourcedir, std::string path, int level);
bool ImportFile(std::string path, std::filesystem::path in);
bool ImportDirectory(std::string sourcedir);
bool DeleteDirectory(const std::string& path, int level);
void CleanupDirectory(const std::string& sourcedir, const std::string& path, int level);
bool ImportFile(const std::string& path, std::filesystem::path in);
bool ImportDirectory(const std::string& sourcedir);
u64 GetDirectorySize(std::filesystem::path sourcedir);
bool Load(std::string filename, u64 size, std::string sourcedir);
bool Load(const std::string& filename, u64 size, const std::string& sourcedir);
bool Save();
typedef struct

View File

@ -377,7 +377,7 @@ bool NeedsDirectBoot()
}
}
void SetupDirectBoot(std::string romname)
void SetupDirectBoot(const std::string& romname)
{
if (ConsoleType == 1)
{

View File

@ -244,7 +244,7 @@ void EjectCart();
bool CartInserted();
bool NeedsDirectBoot();
void SetupDirectBoot(std::string romname);
void SetupDirectBoot(const std::string& romname);
bool LoadGBACart(const u8* romdata, u32 romlen, const u8* savedata, u32 savelen);
void LoadGBAAddon(int type);

View File

@ -232,7 +232,7 @@ void CartCommon::Reset()
DSiMode = false;
}
void CartCommon::SetupDirectBoot(std::string romname)
void CartCommon::SetupDirectBoot(const std::string& romname)
{
CmdEncMode = 2;
DataEncMode = 2;
@ -1217,7 +1217,7 @@ void CartHomebrew::Reset()
SD = nullptr;
}
void CartHomebrew::SetupDirectBoot(std::string romname)
void CartHomebrew::SetupDirectBoot(const std::string& romname)
{
CartCommon::SetupDirectBoot(romname);
@ -1746,7 +1746,7 @@ void LoadSave(const u8* savedata, u32 savelen)
Cart->LoadSave(savedata, savelen);
}
void SetupDirectBoot(std::string romname)
void SetupDirectBoot(const std::string& romname)
{
if (Cart)
Cart->SetupDirectBoot(romname);

View File

@ -40,7 +40,7 @@ public:
virtual u32 Checksum();
virtual void Reset();
virtual void SetupDirectBoot(std::string romname);
virtual void SetupDirectBoot(const std::string& romname);
virtual void DoSavestate(Savestate* file);
@ -161,7 +161,7 @@ private:
u8 IRCmd;
};
// CartRetailBT - Pokémon Typing Adventure (SPI BT controller)
// CartRetailBT - Pok<EFBFBD>mon Typing Adventure (SPI BT controller)
class CartRetailBT : public CartRetail
{
public:
@ -187,7 +187,7 @@ public:
virtual u32 Type() override { return 0x201; }
void Reset() override;
void SetupDirectBoot(std::string romname) override;
void SetupDirectBoot(const std::string& romname) override;
void DoSavestate(Savestate* file) override;
@ -227,7 +227,7 @@ void DecryptSecureArea(u8* out);
bool LoadROM(const u8* romdata, u32 romlen);
void LoadSave(const u8* savedata, u32 savelen);
void SetupDirectBoot(std::string romname);
void SetupDirectBoot(const std::string& romname);
/// This function is intended to allow frontends to save and load SRAM
/// without using melonDS APIs.

View File

@ -108,11 +108,11 @@ bool GetConfigArray(ConfigEntry entry, void* data);
// Looks in the user's data directory first, then the system's.
// If on Windows or a portable UNIX build, this simply calls OpenLocalFile().
FILE* OpenFile(std::string path, std::string mode, bool mustexist=false);
FILE* OpenLocalFile(std::string path, std::string mode);
FILE* OpenDataFile(std::string path);
FILE* OpenFile(const std::string& path, const std::string& mode, bool mustexist=false);
FILE* OpenLocalFile(const std::string& path, const std::string& mode);
FILE* OpenDataFile(const std::string& path);
inline bool FileExists(std::string name)
inline bool FileExists(const std::string& name)
{
FILE* f = OpenFile(name, "rb");
if (!f) return false;
@ -120,7 +120,7 @@ inline bool FileExists(std::string name)
return true;
}
inline bool LocalFileExists(std::string name)
inline bool LocalFileExists(const std::string& name)
{
FILE* f = OpenLocalFile(name, "rb");
if (!f) return false;

View File

@ -49,7 +49,7 @@ using Platform::LogLevel;
// TODO: buffering system! or something of that sort
// repeated fread/fwrite is slow on Switch
Savestate::Savestate(std::string filename, bool save)
Savestate::Savestate(const std::string& filename, bool save)
{
const char* magic = "MELN";

View File

@ -29,7 +29,7 @@
class Savestate
{
public:
Savestate(std::string filename, bool save);
Savestate(const std::string& filename, bool save);
~Savestate();
bool Error;

View File

@ -288,7 +288,7 @@ bool GetConfigArray(ConfigEntry entry, void* data)
}
FILE* OpenFile(std::string path, std::string mode, bool mustexist)
FILE* OpenFile(const std::string& path, const std::string& mode, bool mustexist)
{
QFile f(QString::fromStdString(path));
@ -322,7 +322,7 @@ FILE* OpenFile(std::string path, std::string mode, bool mustexist)
return file;
}
FILE* OpenLocalFile(std::string path, std::string mode)
FILE* OpenLocalFile(const std::string& path, const std::string& mode)
{
QString qpath = QString::fromStdString(path);
QDir dir(qpath);

View File

@ -58,7 +58,7 @@ ARCodeFile* CheatFile = nullptr;
bool CheatsOn = false;
int LastSep(std::string path)
int LastSep(const std::string& path)
{
int i = path.length() - 1;
while (i >= 0)
@ -72,32 +72,45 @@ int LastSep(std::string path)
return -1;
}
std::string GetAssetPath(bool gba, std::string configpath, std::string ext, std::string file="")
std::string GetAssetPath(bool gba, const std::string& configpath, const std::string& ext, const std::string& file = "")
{
std::string result;
if (configpath.empty())
configpath = gba ? BaseGBAROMDir : BaseROMDir;
if (file.empty())
{
file = gba ? BaseGBAAssetName : BaseAssetName;
if (file.empty())
file = "firmware";
}
result = gba ? BaseGBAROMDir : BaseROMDir;
else
result = configpath;
// cut off trailing slashes
for (;;)
{
int i = configpath.length() - 1;
int i = result.length() - 1;
if (i < 0) break;
if (configpath[i] == '/' || configpath[i] == '\\')
configpath = configpath.substr(0, i);
if (result[i] == '/' || result[i] == '\\')
result.resize(i);
else
break;
}
if (!configpath.empty())
configpath += "/";
if (!result.empty())
result += '/';
return configpath + file + ext;
if (file.empty())
{
std::string& baseName = gba ? BaseGBAAssetName : BaseAssetName;
if (baseName.empty())
result += "firmware";
else
result += baseName;
}
else
{
result += file;
}
result += ext;
return result;
}
@ -288,7 +301,7 @@ bool SavestateExists(int slot)
return Platform::FileExists(ssfile);
}
bool LoadState(std::string filename)
bool LoadState(const std::string& filename)
{
// backup
Savestate* backup = new Savestate("timewarp.mln", true);
@ -335,7 +348,7 @@ bool LoadState(std::string filename)
return true;
}
bool SaveState(std::string filename)
bool SaveState(const std::string& filename)
{
Savestate* state = new Savestate(filename, true);
if (state->Error)

View File

@ -49,8 +49,8 @@ QString GBACartLabel();
std::string GetSavestateName(int slot);
bool SavestateExists(int slot);
bool LoadState(std::string filename);
bool SaveState(std::string filename);
bool LoadState(const std::string& filename);
bool SaveState(const std::string& filename);
void UndoStateLoad();
void EnableCheats(bool enable);

View File

@ -25,7 +25,7 @@
using Platform::Log;
using Platform::LogLevel;
SaveManager::SaveManager(std::string path) : QThread()
SaveManager::SaveManager(const std::string& path) : QThread()
{
SecondaryBuffer = nullptr;
SecondaryBufferLength = 0;
@ -71,7 +71,7 @@ std::string SaveManager::GetPath()
return Path;
}
void SaveManager::SetPath(std::string path, bool reload)
void SaveManager::SetPath(const std::string& path, bool reload)
{
Path = path;

View File

@ -34,11 +34,11 @@ class SaveManager : public QThread
void run() override;
public:
SaveManager(std::string path);
SaveManager(const std::string& path);
~SaveManager();
std::string GetPath();
void SetPath(std::string path, bool reload);
void SetPath(const std::string& path, bool reload);
void RequestFlush(const u8* savedata, u32 savelen, u32 writeoffset, u32 writelen);
void CheckFlush();

View File

@ -279,7 +279,7 @@ void micClose()
micDevice = 0;
}
void micLoadWav(std::string name)
void micLoadWav(const std::string& name)
{
SDL_AudioSpec format;
memset(&format, 0, sizeof(SDL_AudioSpec));