mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-12 02:33:08 +02:00
g_strsplit: Use a pre-allocated GArray when max_tokens is provided
In case max_tokens is provided, we can safely pre-allocate the GArray to the max_tokens value plus one for the NULL terminating value.
This commit is contained in:
parent
88d4b3b365
commit
0618f5eb82
@ -2425,9 +2425,15 @@ g_strsplit (const gchar *string,
|
|||||||
g_return_val_if_fail (delimiter[0] != '\0', NULL);
|
g_return_val_if_fail (delimiter[0] != '\0', NULL);
|
||||||
|
|
||||||
if (max_tokens < 1)
|
if (max_tokens < 1)
|
||||||
max_tokens = G_MAXINT;
|
{
|
||||||
|
max_tokens = G_MAXINT;
|
||||||
|
string_list = g_ptr_array_new ();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string_list = g_ptr_array_new_full (max_tokens + 1, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
string_list = g_ptr_array_new ();
|
|
||||||
remainder = string;
|
remainder = string;
|
||||||
s = strstr (remainder, delimiter);
|
s = strstr (remainder, delimiter);
|
||||||
if (s)
|
if (s)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user