mirror of
https://github.com/libretro/RetroArch
synced 2025-03-19 16:21:30 +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);
|
||||||
}
|
}
|
||||||
|
@ -446,12 +446,12 @@ void fill_pathname_resolve_relative(char *out_path, const char *in_refpath,
|
|||||||
* @size : size of output path
|
* @size : size of output path
|
||||||
*
|
*
|
||||||
* Joins a directory (@dir) and path (@path) together.
|
* Joins a directory (@dir) and path (@path) together.
|
||||||
* Makes sure not to get two consecutive slashes
|
* Makes sure not to get two consecutive slashes
|
||||||
* between directory and path.
|
* between directory and path.
|
||||||
*
|
*
|
||||||
* 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