mirror of
https://github.com/libretro/RetroArch
synced 2025-03-20 10:20:51 +00:00
Optimize fill_pathname_join - avoid the call to fill_pathname_slash()
which would have an implicit strlen cost
This commit is contained in:
parent
9d66e2d5e1
commit
605c4608d9
@ -910,11 +910,25 @@ void fill_pathname_resolve_relative(char *out_path,
|
|||||||
size_t fill_pathname_join(char *out_path,
|
size_t fill_pathname_join(char *out_path,
|
||||||
const char *dir, const char *path, size_t size)
|
const char *dir, const char *path, size_t size)
|
||||||
{
|
{
|
||||||
|
size_t len = 0;
|
||||||
if (out_path != dir)
|
if (out_path != dir)
|
||||||
strlcpy(out_path, dir, size);
|
len = strlcpy(out_path, dir, size);
|
||||||
|
|
||||||
if (*out_path)
|
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);
|
return strlcat(out_path, path, size);
|
||||||
}
|
}
|
||||||
|
@ -451,7 +451,7 @@ void fill_pathname_resolve_relative(char *out_path, const char *in_refpath,
|
|||||||
*
|
*
|
||||||
* Hidden non-leaf function cost:
|
* Hidden non-leaf function cost:
|
||||||
* - calls strlcpy
|
* - calls strlcpy
|
||||||
* - calls fill_pathname_slash()
|
* - calls find_last_slash()
|
||||||
* - calls strlcat
|
* - calls strlcat
|
||||||
**/
|
**/
|
||||||
size_t fill_pathname_join(char *out_path, const char *dir,
|
size_t fill_pathname_join(char *out_path, const char *dir,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user