diff options
author | RSDuck <RSDuck@users.noreply.github.com> | 2023-04-28 17:05:34 +0200 |
---|---|---|
committer | RSDuck <RSDuck@users.noreply.github.com> | 2023-04-28 17:05:34 +0200 |
commit | 4b170b94d55d99e8ee9fb8803d9665fdfc2267ae (patch) | |
tree | ef29533d56be441c750ec0ce838624eedb213df5 | |
parent | 3ada5b9bc832cc612a569664de00520f00f7e558 (diff) |
pointless micro optimisations
-rw-r--r-- | src/ARCodeFile.cpp | 2 | ||||
-rw-r--r-- | src/ARCodeFile.h | 2 | ||||
-rw-r--r-- | src/DSi_SD.cpp | 4 | ||||
-rw-r--r-- | src/DSi_SD.h | 4 | ||||
-rw-r--r-- | src/FATStorage.cpp | 27 | ||||
-rw-r--r-- | src/FATStorage.h | 22 | ||||
-rw-r--r-- | src/NDS.cpp | 2 | ||||
-rw-r--r-- | src/NDS.h | 2 | ||||
-rw-r--r-- | src/NDSCart.cpp | 6 | ||||
-rw-r--r-- | src/NDSCart.h | 8 | ||||
-rw-r--r-- | src/Platform.h | 10 | ||||
-rw-r--r-- | src/Savestate.cpp | 2 | ||||
-rw-r--r-- | src/Savestate.h | 2 | ||||
-rw-r--r-- | src/frontend/qt_sdl/Platform.cpp | 4 | ||||
-rw-r--r-- | src/frontend/qt_sdl/ROMManager.cpp | 49 | ||||
-rw-r--r-- | src/frontend/qt_sdl/ROMManager.h | 4 | ||||
-rw-r--r-- | src/frontend/qt_sdl/SaveManager.cpp | 4 | ||||
-rw-r--r-- | src/frontend/qt_sdl/SaveManager.h | 4 | ||||
-rw-r--r-- | src/frontend/qt_sdl/main.cpp | 2 |
19 files changed, 87 insertions, 73 deletions
diff --git a/src/ARCodeFile.cpp b/src/ARCodeFile.cpp index 53a2386..45583ca 100644 --- a/src/ARCodeFile.cpp +++ b/src/ARCodeFile.cpp @@ -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; diff --git a/src/ARCodeFile.h b/src/ARCodeFile.h index f9a1c13..9678926 100644 --- a/src/ARCodeFile.h +++ b/src/ARCodeFile.h @@ -46,7 +46,7 @@ typedef std::list<ARCodeCat> ARCodeCatList; class ARCodeFile { public: - ARCodeFile(std::string filename); + ARCodeFile(const std::string& filename); ~ARCodeFile(); bool Error; diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index f329437..59262cb 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -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; diff --git a/src/DSi_SD.h b/src/DSi_SD.h index 5f6dbcd..75101ed 100644 --- a/src/DSi_SD.h +++ b/src/DSi_SD.h @@ -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(); diff --git a/src/FATStorage.cpp b/src/FATStorage.cpp index 5764524..07cf491 100644 --- a/src/FATStorage.cpp +++ b/src/FATStorage.cpp @@ -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; diff --git a/src/FATStorage.h b/src/FATStorage.h index 29bcbc4..250f023 100644 --- a/src/FATStorage.h +++ b/src/FATStorage.h @@ -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 diff --git a/src/NDS.cpp b/src/NDS.cpp index 215750f..b5c00db 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -377,7 +377,7 @@ bool NeedsDirectBoot() } } -void SetupDirectBoot(std::string romname) +void SetupDirectBoot(const std::string& romname) { if (ConsoleType == 1) { @@ -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); diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index 1e5a45b..83d3bb0 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -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); diff --git a/src/NDSCart.h b/src/NDSCart.h index b9561f0..2718297 100644 --- a/src/NDSCart.h +++ b/src/NDSCart.h @@ -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ďż˝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. diff --git a/src/Platform.h b/src/Platform.h index 2227ffc..e996dea 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -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; diff --git a/src/Savestate.cpp b/src/Savestate.cpp index 7a09617..0aa0ba3 100644 --- a/src/Savestate.cpp +++ b/src/Savestate.cpp @@ -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"; diff --git a/src/Savestate.h b/src/Savestate.h index 51f071a..a2216ce 100644 --- a/src/Savestate.h +++ b/src/Savestate.h @@ -29,7 +29,7 @@ class Savestate { public: - Savestate(std::string filename, bool save); + Savestate(const std::string& filename, bool save); ~Savestate(); bool Error; diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 6b48335..f626c88 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -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); diff --git a/src/frontend/qt_sdl/ROMManager.cpp b/src/frontend/qt_sdl/ROMManager.cpp index ac525b7..cb671e2 100644 --- a/src/frontend/qt_sdl/ROMManager.cpp +++ b/src/frontend/qt_sdl/ROMManager.cpp @@ -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 = "") { - if (configpath.empty()) - configpath = gba ? BaseGBAROMDir : BaseROMDir; + std::string result; - if (file.empty()) - { - file = gba ? BaseGBAAssetName : BaseAssetName; - if (file.empty()) - file = "firmware"; - } + if (configpath.empty()) + 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 += '/'; + + if (file.empty()) + { + std::string& baseName = gba ? BaseGBAAssetName : BaseAssetName; + if (baseName.empty()) + result += "firmware"; + else + result += baseName; + } + else + { + result += file; + } + + result += ext; - return configpath + file + 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) diff --git a/src/frontend/qt_sdl/ROMManager.h b/src/frontend/qt_sdl/ROMManager.h index 9e82a5b..efaed36 100644 --- a/src/frontend/qt_sdl/ROMManager.h +++ b/src/frontend/qt_sdl/ROMManager.h @@ -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); diff --git a/src/frontend/qt_sdl/SaveManager.cpp b/src/frontend/qt_sdl/SaveManager.cpp index 31d2a68..005219b 100644 --- a/src/frontend/qt_sdl/SaveManager.cpp +++ b/src/frontend/qt_sdl/SaveManager.cpp @@ -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; diff --git a/src/frontend/qt_sdl/SaveManager.h b/src/frontend/qt_sdl/SaveManager.h index 0d38f4b..33035ed 100644 --- a/src/frontend/qt_sdl/SaveManager.h +++ b/src/frontend/qt_sdl/SaveManager.h @@ -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(); diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 7015c6d..518d5f5 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -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)); |