Skip to content

Commit 596a8ac

Browse files
committed
(string_list) No more stdstring dependency and optimization
of functions
1 parent 71ec243 commit 596a8ac

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

libretro-common/lists/string_list.c

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2121
*/
2222

23-
#include <stdio.h>
2423
#include <stdint.h>
2524
#include <string.h>
25+
#include <ctype.h>
2626

2727
#include <lists/string_list.h>
2828
#include <compat/strl.h>
2929
#include <compat/posix_string.h>
30-
#include <string/stdstring.h>
3130

3231
static bool string_list_deinitialize_internal(struct string_list *list)
3332
{
@@ -349,13 +348,20 @@ bool string_split_noalloc(struct string_list *list,
349348

350349
int string_list_find_elem(const struct string_list *list, const char *elem)
351350
{
352-
if (list)
351+
if (list && elem)
353352
{
354353
size_t i;
355354
for (i = 0; i < list->size; i++)
356355
{
357-
if (string_is_equal_noncase(list->elems[i].data, elem))
358-
return (int)(i + 1);
356+
const unsigned char *p1 = (const unsigned char*)list->elems[i].data;
357+
const unsigned char *p2 = (const unsigned char*)elem;
358+
while ((*p1 | 32) == (*p2 | 32) || (*p1 == *p2))
359+
{
360+
if (*p1 == '\0')
361+
return (int)(i + 1);
362+
p1++;
363+
p2++;
364+
}
359365
}
360366
}
361367
return 0;
@@ -372,9 +378,26 @@ bool string_list_find_elem_prefix(const struct string_list *list,
372378
strlcpy(prefixed + _len, elem, sizeof(prefixed) - _len);
373379
for (i = 0; i < list->size; i++)
374380
{
375-
if ( string_is_equal_noncase(list->elems[i].data, elem)
376-
|| string_is_equal_noncase(list->elems[i].data, prefixed))
377-
return true;
381+
const char *data = list->elems[i].data;
382+
const char *a = data;
383+
const char *b = elem;
384+
while (tolower((unsigned char)*a) == tolower((unsigned char)*b))
385+
{
386+
if (*a == '\0')
387+
return true;
388+
a++;
389+
b++;
390+
}
391+
392+
a = data;
393+
b = prefixed;
394+
while (tolower((unsigned char)*a) == tolower((unsigned char)*b))
395+
{
396+
if (*a == '\0')
397+
return true;
398+
a++;
399+
b++;
400+
}
378401
}
379402
}
380403
return false;

0 commit comments

Comments
 (0)