More ConvertToWinPath/ConvertToUnixPath optimizations

Don't allocate static buffer on the stack, use the result string instead.
This commit is contained in:
Kawe Mazidjatari 2022-08-09 14:00:51 +02:00
parent 5334f31644
commit e97b4e53b2

View File

@ -309,38 +309,34 @@ string CreateDirectories(string svInput, bool bWindows)
// For converting filepaths to windows filepaths.
string ConvertToWinPath(const string& svInput)
{
char szFilePath[MAX_PATH];
string results;
sprintf_s(szFilePath, MAX_PATH, "%s", svInput.c_str());
string results = svInput;
// Flip forward slashes in filepath to windows-style backslash
for (size_t i = 0, len = strlen(szFilePath); i < len; i++)
for (size_t i = 0; i < results.size(); i++)
{
if (szFilePath[i] == '/')
if (results[i] == '/')
{
szFilePath[i] = '\\';
results[i] = '\\';
}
}
return results = szFilePath;
return results;
}
///////////////////////////////////////////////////////////////////////////////
// For converting filepaths to unix filepaths.
string ConvertToUnixPath(const string& svInput)
{
char szFilePath[MAX_PATH];
string results;
sprintf_s(szFilePath, MAX_PATH, "%s", svInput.c_str());
string results = svInput;
// Flip windows-style backslashes in filepath to forward slash
for (size_t i = 0, len = strlen(szFilePath); i < len; i++)
for (size_t i = 0; i < results.size(); i++)
{
if (szFilePath[i] == '\\')
if (results[i] == '\\')
{
szFilePath[i] = '/';
results[i] = '/';
}
}
return results = szFilePath;
return results;
}
///////////////////////////////////////////////////////////////////////////////