Skip to content

Commit 69b8e46

Browse files
committed
Faster versions of string_is_equal and string_is_equal_case_insensitive
1 parent 1a8071a commit 69b8e46

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

libretro-common/include/string/stdstring.h

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ static INLINE bool string_is_empty(const char *data)
6464

6565
static INLINE bool string_is_equal(const char *a, const char *b)
6666
{
67-
return (a && b) ? !strcmp(a, b) : false;
67+
if (a == b)
68+
return true;
69+
if (!a || !b)
70+
return false;
71+
return !strcmp(a, b);
6872
}
6973

7074
static INLINE bool string_starts_with_size(const char *str, const char *prefix,
@@ -109,24 +113,14 @@ static INLINE size_t strlen_size(const char *str, size_t len)
109113
return i;
110114
}
111115

112-
113116
static INLINE bool string_is_equal_case_insensitive(const char *a,
114117
const char *b)
115118
{
116-
int result = 0;
117-
const unsigned char *p1 = (const unsigned char*)a;
118-
const unsigned char *p2 = (const unsigned char*)b;
119-
119+
if (a == b)
120+
return true;
120121
if (!a || !b)
121122
return false;
122-
if (p1 == p2)
123-
return true;
124-
125-
while ((result = tolower (*p1) - tolower (*p2++)) == 0)
126-
if (*p1++ == '\0')
127-
break;
128-
129-
return (result == 0);
123+
return strcasecmp(a, b) == 0;
130124
}
131125

132126
static INLINE bool string_starts_with_case_insensitive(const char *str,

0 commit comments

Comments
 (0)