Optimize fill_pathname_join - avoid the call to fill_pathname_slash()

which would have an implicit strlen cost
This commit is contained in:
LibretroAdmin 2022-08-01 22:14:26 +02:00
parent 9d66e2d5e1
commit 605c4608d9
2 changed files with 18 additions and 4 deletions

View File

@ -910,11 +910,25 @@ void fill_pathname_resolve_relative(char *out_path,
size_t fill_pathname_join(char *out_path,
const char *dir, const char *path, size_t size)
{
size_t len = 0;
if (out_path != dir)
strlcpy(out_path, dir, size);
len = strlcpy(out_path, dir, size);
if (*out_path)
fill_pathname_slash(out_path, size);
{
const char *last_slash = find_last_slash(out_path);
if (last_slash)
{
/* Try to preserve slash type. */
if (last_slash != (out_path + len - 1))
{
out_path[len] = last_slash[0];
out_path[len+1] = '\0';
}
}
else
strlcat(out_path, PATH_DEFAULT_SLASH(), size);
}
return strlcat(out_path, path, size);
}

View File

@ -451,7 +451,7 @@ void fill_pathname_resolve_relative(char *out_path, const char *in_refpath,
*
* Hidden non-leaf function cost:
* - calls strlcpy
* - calls fill_pathname_slash()
* - calls find_last_slash()
* - calls strlcat
**/
size_t fill_pathname_join(char *out_path, const char *dir,