From f522cfcce89adab5100178193094ea5bc0ab981f Mon Sep 17 00:00:00 2001 From: jdgleaver Date: Thu, 21 May 2020 13:28:42 +0100 Subject: [PATCH] Optimise 'path_is_absolute()' --- libretro-common/file/file_path.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index 866d54e4cd..a6a464d786 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -621,19 +621,29 @@ const char *path_basename(const char *path) **/ bool path_is_absolute(const char *path) { +#if defined(__wiiu__) || defined(VITA) + const char *seperator = NULL; +#endif + + if (string_is_empty(path)) + return false; + if (path[0] == '/') return true; -#ifdef _WIN32 - /* Many roads lead to Rome ... */ - if (( strstr(path, "\\\\") == path) - || strstr(path, ":/") - || strstr(path, ":\\") - || strstr(path, ":\\\\")) + +#if defined(_WIN32) + /* Many roads lead to Rome... + * Note: Drive letter can only be 1 character long */ + if (string_starts_with(path, "\\\\") || + string_starts_with(path + 1, ":/") || + string_starts_with(path + 1, ":\\")) return true; #elif defined(__wiiu__) || defined(VITA) - if (strstr(path, ":/")) + seperator = strchr(path, ':'); + if (seperator && (seperator[1] == '/')) return true; #endif + return false; }