ConvertToWinPath and ConvertToUnixPath optimizations

* Don't compute strlen on each iteration.
This commit is contained in:
Kawe Mazidjatari 2022-08-09 13:50:43 +02:00
parent f14d588d0a
commit 5334f31644

View File

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