mirror of
https://github.com/GerbilSoft/rom-properties.git
synced 2025-06-18 19:45:41 -04:00
[libromdata] IsoPartition: Optimize findLastSlash() by searching for '/' and '\\' at the same time instead of calling strrchr() twice.
This commit is contained in:
parent
c7ccd7a39a
commit
a49fb884f1
@ -57,6 +57,15 @@ public:
|
||||
// IFst::Dir* reference counter
|
||||
int fstDirCount;
|
||||
|
||||
/**
|
||||
* Is this character a slash or backslash?
|
||||
* @return True if it is; false if it isn't.
|
||||
*/
|
||||
static inline bool is_slash(char c)
|
||||
{
|
||||
return (c == '/') || (c == '\\');
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the last slash or backslash in a path.
|
||||
* @param path Path
|
||||
@ -64,14 +73,14 @@ public:
|
||||
*/
|
||||
static inline const char *findLastSlash(const char *path)
|
||||
{
|
||||
const char *sl = strrchr(path, '/');
|
||||
const char *const bs = strrchr(path, '\\');
|
||||
if (sl && bs) {
|
||||
if (bs > sl) {
|
||||
sl = bs;
|
||||
size_t size = strlen(path);
|
||||
const char *p = path + size - 1;
|
||||
for (; size > 0; size--, p--) {
|
||||
if (is_slash(*p)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return (sl) ? sl : bs;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user