mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
strfuncs: a few g_strsplit_set() improvements
gboolean is secretly actually typedef gint gboolean, so the delim_table is going to take 1KB of stack all by itself. That’s fine, but it could be smaller. This strnpbrk()-like block could do with a comment to make it a bit clearer what it’s doing. Suggested-by: Philip Withnall <philip@tecnocode.co.uk> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
1ee22d0ae9
commit
db9987d269
@ -2393,7 +2393,8 @@ g_strsplit (const gchar *string,
|
|||||||
* g_strsplit_set:
|
* g_strsplit_set:
|
||||||
* @string: The string to be tokenized
|
* @string: The string to be tokenized
|
||||||
* @delimiters: A nul-terminated string containing bytes that are used
|
* @delimiters: A nul-terminated string containing bytes that are used
|
||||||
* to split the string.
|
* to split the string (it can accept an empty string, which will result
|
||||||
|
* in no string splitting).
|
||||||
* @max_tokens: The maximum number of tokens to split @string into.
|
* @max_tokens: The maximum number of tokens to split @string into.
|
||||||
* If this is less than 1, the string is split completely
|
* If this is less than 1, the string is split completely
|
||||||
*
|
*
|
||||||
@ -2429,7 +2430,7 @@ g_strsplit_set (const gchar *string,
|
|||||||
const gchar *delimiters,
|
const gchar *delimiters,
|
||||||
gint max_tokens)
|
gint max_tokens)
|
||||||
{
|
{
|
||||||
gboolean delim_table[256];
|
guint8 delim_table[256]; /* 1 = index is a separator; 0 otherwise */
|
||||||
GSList *tokens, *list;
|
GSList *tokens, *list;
|
||||||
gint n_tokens;
|
gint n_tokens;
|
||||||
const gchar *s;
|
const gchar *s;
|
||||||
@ -2450,6 +2451,9 @@ g_strsplit_set (const gchar *string,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check if each character in @string is a separator, by indexing by the
|
||||||
|
* character value into the @delim_table, which has value 1 stored at an index
|
||||||
|
* if that index is a separator. */
|
||||||
memset (delim_table, FALSE, sizeof (delim_table));
|
memset (delim_table, FALSE, sizeof (delim_table));
|
||||||
for (s = delimiters; *s != '\0'; ++s)
|
for (s = delimiters; *s != '\0'; ++s)
|
||||||
delim_table[*(guchar *)s] = TRUE;
|
delim_table[*(guchar *)s] = TRUE;
|
||||||
|
Loading…
Reference in New Issue
Block a user