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

@ -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));