Skip to content

Commit

Permalink
pointless micro optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
RSDuck committed Apr 28, 2023
1 parent 3ada5b9 commit 4b170b9
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/ARCodeFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/ARCodeFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ typedef std::list<ARCodeCat> ARCodeCatList;
class ARCodeFile
{
public:
ARCodeFile(std::string filename);
ARCodeFile(const std::string& filename);
~ARCodeFile();

bool Error;
Expand Down
4 changes: 2 additions & 2 deletions src/DSi_SD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/DSi_SD.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ class DSi_SDDevice
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();
Expand Down
27 changes: 14 additions & 13 deletions src/FATStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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:");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 11 additions & 11 deletions src/FATStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -62,19 +62,19 @@ class FATStorage
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
Expand Down
2 changes: 1 addition & 1 deletion src/NDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ bool NeedsDirectBoot()
}
}

void SetupDirectBoot(std::string romname)
void SetupDirectBoot(const std::string& romname)
{
if (ConsoleType == 1)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NDS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/NDSCart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/NDSCart.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CartCommon
virtual u32 Checksum();

virtual void Reset();
virtual void SetupDirectBoot(std::string romname);
virtual void SetupDirectBoot(const std::string& romname);

virtual void DoSavestate(Savestate* file);

Expand Down Expand Up @@ -161,7 +161,7 @@ class CartRetailIR : public CartRetail
u8 IRCmd;
};

// CartRetailBT - Pokémon Typing Adventure (SPI BT controller)
// CartRetailBT - Pok�mon Typing Adventure (SPI BT controller)
class CartRetailBT : public CartRetail
{
public:
Expand All @@ -187,7 +187,7 @@ class CartHomebrew : public CartCommon
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;

Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions src/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,19 @@ 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;
fclose(f);
return true;
}

inline bool LocalFileExists(std::string name)
inline bool LocalFileExists(const std::string& name)
{
FILE* f = OpenLocalFile(name, "rb");
if (!f) return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Savestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 1 addition & 1 deletion src/Savestate.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class Savestate
{
public:
Savestate(std::string filename, bool save);
Savestate(const std::string& filename, bool save);
~Savestate();

bool Error;
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/qt_sdl/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 4b170b9

Please sign in to comment.