st-theme: Optimize string_in_list

Rather than using a complicated set of function calls across
library boundaries and our own scanning logic, use strtok(),
which glibc already provides, and is probably much more optimized.

https://bugzilla.gnome.org/show_bug.cgi?id=687465
This commit is contained in:
Jasper St. Pierre 2012-11-05 13:36:40 -05:00
parent d88002c4ed
commit 73b4a0ef5f

View File

@ -450,26 +450,26 @@ static gboolean
string_in_list (GString *stryng, string_in_list (GString *stryng,
const char *list) const char *list)
{ {
const char *cur; char *cur;
char *l = g_strdup (list);
char *temp;
gboolean found = FALSE;
for (cur = list; *cur;) cur = strtok_r (l, " \t\f\r\n", &temp);
while (cur != NULL)
{ {
while (*cur && cr_utils_is_white_space (*cur)) if (!strqcmp (cur, stryng->str, stryng->len))
cur++;
if (strncmp (cur, stryng->str, stryng->len) == 0)
{ {
cur += stryng->len; found = TRUE;
if ((!*cur) || cr_utils_is_white_space (*cur)) goto out;
return TRUE;
} }
/* skip to next whitespace character */ cur = strtok_r (NULL, " \t\f\r\n", &temp);
while (*cur && !cr_utils_is_white_space (*cur))
cur++;
} }
return FALSE; out:
g_free (l);
return found;
} }
static gboolean static gboolean